sklearn.svm.OneClassSVMclass sklearn.svm.OneClassSVM(*, kernel='rbf', degree=3, gamma='scale', coef0=0.0, tol=0.001, nu=0.5, shrinking=True, cache_size=200, verbose=False, max_iter=- 1) [来源]
无监督外差检测。 估计高维分布的支持度。 它的实现是基于libsvm的。 在《用户指南》中阅读更多内容。 Parameters kernel{'linear’, 'poly’, 'rbf’, 'sigmoid’, 'precomputed’}, default=’rbf’
指定算法中要使用的内核类型。它必须是“线性”,“多边形”,“ rbf”,“ Sigmoid”,“预先计算”或可调用的一个。如果没有给出,将使用“ rbf”。如果给出了可调用对象,则将其用于预先计算内核矩阵。 degreeint, default=3
多项式内核函数的度(“ poly”)。被所有其他内核忽略。 gamma{'scale’, 'auto’} or float, default=’scale’
“ rbf”,“ poly”和“ Sigmoid”的内核系数。 在版本0.22中更改: gamma 的默认值从“自动”更改为“缩放”。 coef0float, default=0.0
内核函数中的独立术语。它仅在“ poly”和“ Sigmoid”中有意义。 tolfloat, default=1e-3
停止标准的公差。 nufloat, default=0.5
训练误差分数的上界和支持向量分数的下界。应该在区间(0,1]中。默认取0.5。 shrinkingbool, default=True
是否使用缩小的启发式方法。请参阅《用户指南》。 cache_sizefloat, default=200
指定内核缓存的大小(单位:MB)。 verbosebool, default=False
启用verbose输出。请注意,此设置利用了 libsvm 中的每进程运行时设置,如果启用,可能无法在多线程环境中正常工作。 max_iterint, default=-1
对求解器内的迭代进行硬限制,如果没有限制,则为-1。
Attributes class_weight_ndarray of shape (n_classes,)
每个类的参数C的乘数。根据 class_weight 参数进行计算。 coef_ndarray of shape (1, n_features)
分配给特征的权重(原始问题中的系数)。这只有在线性核的情况下才有。 coef_ 是从 dual_coef_ 和 support_vectors_ 派生的只读属性。
dual_coef_ndarray of shape (1, n_SV)
决策函数中支持向量的系数。 fit_status_int
如果安装正确,则为0,否则为1(将发出警告)。 intercept_ndarray of shape (1,)
决策函数中的常数。 n_support_ndarray of shape (n_classes,), dtype=int32
每个类的支持向量的数量。 offset_float
偏移量用于根据原始分数定义决策函数。我们具有以下关系:Decision_function = score_samples- offset_ 。偏移量与 intercept_ 相反,并且为与其他异常值检测算法保持一致而提供。 0.20版本的新内容。 shape_fit_tuple of int of shape (n_dimensions_of_X,)
训练向量 X 的数组维数。 support_ndarray of shape (n_SV,)
支持向量的指数。 support_vectors_ndarray of shape (n_SV, n_features)
支持向量。
Examples>>> from sklearn.svm import OneClassSVM>>> X = [[0], [0.44], [0.45], [0.46], [1]]>>> clf = OneClassSVM(gamma='auto').fit(X)>>> clf.predict(X)array([-1, 1, 1, 1, -1])>>> clf.score_samples(X)array([1.7798..., 2.0547..., 2.0556..., 2.0561..., 1.7332...]) Methodspredict(X) [source]
对X中的样本进行分类。 对于单类模型,返回+1或-1。 Parameters X{array-like, sparse matrix} of shape (n_samples, n_features) or (n_samples_test, n_samples_train)
对于内核=“预先计算”,X的预期形状为(n_samples_test,n_samples_train)。
Returns
使用 sklearn.svm.OneClassSVM 的示例
|