OneClassSVM
- class sklearn.svm.OneClassSVM(*, kernel='rbf', degree=3, gamma='scale', coef0=0.0, tol=0.001, nu=, , , ,
Unsupervised Outlier Detection.
Estimate the support of a high-dimensional distribution.
The implementation is based on libsvm.
Read more in the User Guide.
Specifies the kernel type to be used in the algorithm. If none is given, ‘rbf’ will be used. If a callable is given it is used to precompute the kernel matrix.
Degree of the polynomial kernel function (‘poly’). Must be non-negative. Ignored by all other kernels.
Kernel coefficient for ‘rbf’, ‘poly’ and ‘sigmoid’.
if gamma='scale' (default) is passed then it uses
1 / (n_features * X.var()) as value of gamma,
if ‘auto’, uses 1 / n_features
if float, must be non-negative.
Independent term in kernel function. It is only significant in ‘poly’ and ‘sigmoid’.
Tolerance for stopping criterion.
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.
Whether to use the shrinking heuristic. See the User Guide.
Specify the size of the kernel cache (in MB).
Enable verbose output. Note that this setting takes advantage of a per-process runtime setting in libsvm that, if enabled, may not work properly in a multithreaded context.
Hard limit on iterations within solver, or -1 for no limit.
coef_ : ndarray or sparse array/matrix of shape (1, n_features)Weights assigned to the features when kernel="linear".
Coefficients of the support vectors in the decision function.
If X is sparse, these will also be sparse.
0 if correctly fitted, 1 otherwise (will raise warning)
Constant in the decision function.
>>> from sklearn.svm import OneClassSVM
>>> X = [[0], [0.44], [0.45], [0.46], [1]]
>>> clf = OneClassSVM(gamma='auto').fit(X
For a more extended example, see Species distribution modeling
Signed distance to the separating hyperplane.
Signed distance is positive for an inlier and negative for an outlier.
The data matrix.
Returns the decision function of the samples.
Detect the soft boundary of the set of samples X.
Set of samples, where n_samples is the number of samples and
n_features is the number of features.
Perform fit on X and returns labels for X.
Returns -1 for outliers and 1 for inliers.
The input samples.
Not used, present for API consistency by convention.
Get metadata routing of this object.
Please check User Guide on how the routing mechanism works.
A MetadataRequest encapsulating
routing information.
Get parameters for this estimator.
If True, will return the parameters for this estimator and contained subobjects that are estimators.
Parameter names mapped to their values.
Perform classification on samples in X.
For a one-class model, +1 or -1 is returned.
For kernel=”precomputed”, the expected shape of X is (n_samples_test, n_samples_train).
Class labels for samples in X.
Raw scoring function of the samples.
The data matrix.
Returns the (unshifted) scoring function of the samples.
Configure whether metadata should be requested to be passed to the method.
Set the parameters of this estimator.
The method works on simple estimators as well as on nested objects
(such as Pipeline). The latter have
parameters of the form <component>__<parameter> so that it’s
possible to update each component of a nested object.
Estimator parameters.
One-Class SVM versus One-Class SVM using Stochastic Gradient Descent
Comparing anomaly detection algorithms for outlier detection on toy datasets
n_features_in_,)Names of features seen during fit. Defined only when X
has feature names that are all strings.
Number of iterations run by the optimization routine to fit the model.
n_support_ : ndarray of shape (n_classes,), dtype=int32Number of support vectors for each class.
Offset used to define the decision function from the raw scores.
We have the relation: decision_function = score_samples - offset_.
The offset is the opposite of intercept_ and is provided for
consistency with other outlier detection algorithms.
Array dimensions of training vector X.
Indices of support vectors.
Support vectors.
If X is sparse, these will also be sparse.
Not used, present for API consistency by convention.
Per-sample weights. Rescale C per sample. Higher weights force the classifier to put more emphasis on these points.
Fitted estimator.
If X is not a C-ordered contiguous array it is copied.
Arguments to be passed to fit.
1 for inliers, -1 for outliers.
Note that this method is only relevant when this estimator is used as a
sub-estimator within a meta-estimator and metadata routing is enabled
with enable_metadata_routing=True (see sklearn.set_config).
Please check the User Guide on how the routing
mechanism works.
The options for each parameter are:
True: metadata is requested, and passed to fit if provided. The request is ignored if metadata is not provided.
False: metadata is not requested and the meta-estimator will not pass it to fit.
None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.
str: metadata should be passed to the meta-estimator with this given alias instead of the original name.
The default (sklearn.utils.metadata_routing.UNCHANGED) retains the
existing request. This allows you to change the request for some
parameters and not others.
Metadata routing for sample_weight parameter in fit.
The updated object.
Estimator instance.