DocumentationClassesSGDOneClassSVM

Class: SGDOneClassSVM

Solves linear One-Class SVM using Stochastic Gradient Descent.

This implementation is meant to be used with a kernel approximation technique (e.g. sklearn.kernel_approximation.Nystroem) to obtain results similar to sklearn.svm.OneClassSVM which uses a Gaussian kernel by default.

Read more in the User Guide.

Python Reference

Constructors

new SGDOneClassSVM()

new SGDOneClassSVM(opts?): SGDOneClassSVM

Parameters

ParameterTypeDescription
opts?object-
opts.average?number | booleanWhen set to true, computes the averaged SGD weights and stores the result in the coef_ attribute. If set to an int greater than 1, averaging will begin once the total number of samples seen reaches average. So average=10 will begin averaging after seeing 10 samples.
opts.eta0?numberThe initial learning rate for the ‘constant’, ‘invscaling’ or ‘adaptive’ schedules. The default value is 0.0 as eta0 is not used by the default schedule ‘optimal’. Values must be in the range \[0.0, inf).
opts.fit_intercept?booleanWhether the intercept should be estimated or not. Defaults to true.
opts.learning_rate?"constant" | "optimal" | "invscaling" | "adaptive"The learning rate schedule to use with fit. (If using partial_fit, learning rate must be controlled directly).
opts.max_iter?numberThe maximum number of passes over the training data (aka epochs). It only impacts the behavior in the fit method, and not the partial_fit. Defaults to 1000. Values must be in the range \[1, inf).
opts.nu?numberThe nu parameter of the One Class SVM: an upper bound on the fraction of training errors and a lower bound of the fraction of support vectors. Should be in the interval (0, 1]. By default 0.5 will be taken.
opts.power_t?numberThe exponent for inverse scaling learning rate. Values must be in the range (-inf, inf).
opts.random_state?numberThe seed of the pseudo random number generator to use when shuffling the data. If int, random_state is the seed used by the random number generator; If RandomState instance, random_state is the random number generator; If undefined, the random number generator is the RandomState instance used by np.random.
opts.shuffle?booleanWhether or not the training data should be shuffled after each epoch. Defaults to true.
opts.tol?numberThe stopping criterion. If it is not undefined, the iterations will stop when (loss > previous_loss - tol). Defaults to 1e-3. Values must be in the range \[0.0, inf).
opts.verbose?numberThe verbosity level.
opts.warm_start?booleanWhen set to true, reuse the solution of the previous call to fit as initialization, otherwise, just erase the previous solution. See the Glossary. Repeatedly calling fit or partial_fit when warm_start is true can result in a different solution than when calling fit a single time because of the way the data is shuffled. If a dynamic learning rate is used, the learning rate is adapted depending on the number of samples already seen. Calling fit resets this counter, while partial_fit will result in increasing the existing counter.

Returns SGDOneClassSVM

Defined in generated/linear_model/SGDOneClassSVM.ts:25

Properties

PropertyTypeDefault valueDefined in
_isDisposedbooleanfalsegenerated/linear_model/SGDOneClassSVM.ts:23
_isInitializedbooleanfalsegenerated/linear_model/SGDOneClassSVM.ts:22
_pyPythonBridgeundefinedgenerated/linear_model/SGDOneClassSVM.ts:21
idstringundefinedgenerated/linear_model/SGDOneClassSVM.ts:18
optsanyundefinedgenerated/linear_model/SGDOneClassSVM.ts:19

Accessors

coef_

Get Signature

get coef_(): Promise<ArrayLike[]>

Weights assigned to the features.

Returns Promise<ArrayLike[]>

Defined in generated/linear_model/SGDOneClassSVM.ts:603


feature_names_in_

Get Signature

get feature_names_in_(): Promise<ArrayLike>

Names of features seen during fit. Defined only when X has feature names that are all strings.

Returns Promise<ArrayLike>

Defined in generated/linear_model/SGDOneClassSVM.ts:749


loss_function_

Get Signature

get loss_function_(): Promise<any>

Deprecated since version 1.4: loss_function_ was deprecated in version 1.4 and will be removed in 1.6.

Returns Promise<any>

Defined in generated/linear_model/SGDOneClassSVM.ts:699


n_features_in_

Get Signature

get n_features_in_(): Promise<number>

Number of features seen during fit.

Returns Promise<number>

Defined in generated/linear_model/SGDOneClassSVM.ts:724


n_iter_

Get Signature

get n_iter_(): Promise<number>

The actual number of iterations to reach the stopping criterion.

Returns Promise<number>

Defined in generated/linear_model/SGDOneClassSVM.ts:651


offset_

Get Signature

get offset_(): Promise<ArrayLike>

Offset used to define the decision function from the raw scores. We have the relation: decision_function = score_samples - offset.

Returns Promise<ArrayLike>

Defined in generated/linear_model/SGDOneClassSVM.ts:626


py

Get Signature

get py(): PythonBridge

Returns PythonBridge

Set Signature

set py(pythonBridge): void

Parameters

ParameterType
pythonBridgePythonBridge

Returns void

Defined in generated/linear_model/SGDOneClassSVM.ts:114


t_

Get Signature

get t_(): Promise<number>

Number of weight updates performed during training. Same as (n_iter_ \* n_samples + 1).

Returns Promise<number>

Defined in generated/linear_model/SGDOneClassSVM.ts:676

Methods

decision_function()

decision_function(opts): Promise<ArrayLike>

Signed distance to the separating hyperplane.

Signed distance is positive for an inlier and negative for an outlier.

Parameters

ParameterTypeDescription
optsobject-
opts.X?anyTesting data.

Returns Promise<ArrayLike>

Defined in generated/linear_model/SGDOneClassSVM.ts:185


densify()

densify(opts): Promise<any>

Convert coefficient matrix to dense array format.

Converts the coef_ member (back) to a numpy.ndarray. This is the default format of coef_ and is required for fitting, so calling this method is only required on models that have previously been sparsified; otherwise, it is a no-op.

Parameters

ParameterType
optsobject

Returns Promise<any>

Defined in generated/linear_model/SGDOneClassSVM.ts:221


dispose()

dispose(): Promise<void>

Disposes of the underlying Python resources.

Once dispose() is called, the instance is no longer usable.

Returns Promise<void>

Defined in generated/linear_model/SGDOneClassSVM.ts:166


fit()

fit(opts): Promise<any>

Fit linear One-Class SVM with Stochastic Gradient Descent.

This solves an equivalent optimization problem of the One-Class SVM primal optimization problem and returns a weight vector w and an offset rho such that the decision function is given by <w, x> - rho.

Parameters

ParameterTypeDescription
optsobject-
opts.coef_init?anyThe initial coefficients to warm-start the optimization.
opts.offset_init?anyThe initial offset to warm-start the optimization.
opts.sample_weight?ArrayLikeWeights applied to individual samples. If not provided, uniform weights are assumed. These weights will be multiplied with class_weight (passed through the constructor) if class_weight is specified.
opts.X?anyTraining data.
opts.y?anyNot used, present for API consistency by convention.

Returns Promise<any>

Defined in generated/linear_model/SGDOneClassSVM.ts:249


fit_predict()

fit_predict(opts): Promise<ArrayLike>

Perform fit on X and returns labels for X.

Returns -1 for outliers and 1 for inliers.

Parameters

ParameterTypeDescription
optsobject-
opts.kwargs?anyArguments to be passed to fit.
opts.X?ArrayLikeThe input samples.
opts.y?anyNot used, present for API consistency by convention.

Returns Promise<ArrayLike>

Defined in generated/linear_model/SGDOneClassSVM.ts:303


get_metadata_routing()

get_metadata_routing(opts): Promise<any>

Get metadata routing of this object.

Please check User Guide on how the routing mechanism works.

Parameters

ParameterTypeDescription
optsobject-
opts.routing?anyA MetadataRequest encapsulating routing information.

Returns Promise<any>

Defined in generated/linear_model/SGDOneClassSVM.ts:347


init()

init(py): Promise<void>

Initializes the underlying Python resources.

This instance is not usable until the Promise returned by init() resolves.

Parameters

ParameterType
pyPythonBridge

Returns Promise<void>

Defined in generated/linear_model/SGDOneClassSVM.ts:127


partial_fit()

partial_fit(opts): Promise<any>

Fit linear One-Class SVM with Stochastic Gradient Descent.

Parameters

ParameterTypeDescription
optsobject-
opts.sample_weight?ArrayLikeWeights applied to individual samples. If not provided, uniform weights are assumed.
opts.X?anySubset of the training data.
opts.y?anyNot used, present for API consistency by convention.

Returns Promise<any>

Defined in generated/linear_model/SGDOneClassSVM.ts:381


predict()

predict(opts): Promise<any>

Return labels (1 inlier, -1 outlier) of the samples.

Parameters

ParameterTypeDescription
optsobject-
opts.X?anyTesting data.

Returns Promise<any>

Defined in generated/linear_model/SGDOneClassSVM.ts:423


score_samples()

score_samples(opts): Promise<ArrayLike>

Raw scoring function of the samples.

Parameters

ParameterTypeDescription
optsobject-
opts.X?anyTesting data.

Returns Promise<ArrayLike>

Defined in generated/linear_model/SGDOneClassSVM.ts:455


set_fit_request()

set_fit_request(opts): Promise<any>

Request metadata passed to the fit method.

Note that this method is only relevant if enable_metadata_routing=True (see sklearn.set_config). Please see User Guide on how the routing mechanism works.

The options for each parameter are:

Parameters

ParameterTypeDescription
optsobject-
opts.coef_init?string | booleanMetadata routing for coef_init parameter in fit.
opts.offset_init?string | booleanMetadata routing for offset_init parameter in fit.
opts.sample_weight?string | booleanMetadata routing for sample_weight parameter in fit.

Returns Promise<any>

Defined in generated/linear_model/SGDOneClassSVM.ts:491


set_partial_fit_request()

set_partial_fit_request(opts): Promise<any>

Request metadata passed to the partial_fit method.

Note that this method is only relevant if enable_metadata_routing=True (see sklearn.set_config). Please see User Guide on how the routing mechanism works.

The options for each parameter are:

Parameters

ParameterTypeDescription
optsobject-
opts.sample_weight?string | booleanMetadata routing for sample_weight parameter in partial_fit.

Returns Promise<any>

Defined in generated/linear_model/SGDOneClassSVM.ts:539


sparsify()

sparsify(opts): Promise<any>

Convert coefficient matrix to sparse format.

Converts the coef_ member to a scipy.sparse matrix, which for L1-regularized models can be much more memory- and storage-efficient than the usual numpy.ndarray representation.

The intercept_ member is not converted.

Parameters

ParameterType
optsobject

Returns Promise<any>

Defined in generated/linear_model/SGDOneClassSVM.ts:577