分享

SVM参数

 医学数据科学 2022-06-22 发布于天津

sklearn.svm.OneClassSVM

  • class 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”的内核系数。

        • 如果传递了 gamma='scale' (默认值),则它将1 /(n_features * X.var())用作gamma值,

        • 如果为'auto',则使用1 / n_features。

        在版本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...])

    Methods

    decision_function(X)

    到分离超平面的符号距离。

    fit (X [,y,sample_weight])

    检测样本集X的软边界。

    fit_predict (X [,y])

    对X进行拟合,并返回X的标签。

    get_params([deep])

    获取该估计器的参数。

    predict(X)

    对X中的样本进行分类。

    score_samples(X)

    样本的原始评分功能。

    set_params(**params)

    设置该估计器的参数。

    • decision_function(X)[source]

    • 到分离超平面的符号距离。

      有符号的距离,对内者为正,对外者为负。

      • Parameters

        • Xarray-like of shape (n_samples, n_features)

        • 数据矩阵。

      • Returns

        • decndarray of shape (n_samples,)

        • 返回样本的决策函数。

    • fit(X, y=None, sample_weight=None, **params) [来源]

    • 检测样本集X的软边界。

      • Parameters

        • X{array-like, sparse matrix} of shape (n_samples, n_features)

        • 样本集,其中n_samples为样本数,n_features为特征数。

        • sample_weightarray-like of shape (n_samples,), default=None

        • 每个样本的权重。重新调整每个样本的C。较高的权重迫使分类器更加重视这些点。

        • yIgnored

        • 不使用,为了保持API的一致性而约定使用。

      • Returns

        • selfobject

      Notes

      如果X不是一个C顺序的连续数组,就会被复制。

    • fit_predict(X, y=None)[source]

    • 对X进行拟合,并返回X的标签。

      离群值为-1,离群值为1。

      • Parameters

        • X{array-like, sparse matrix, dataframe} of shape (n_samples, n_features)

        • yIgnored

        • 未使用,按惯例为API一致性而存在。

      • Returns

        • yndarray of shape (n_samples,)

        • 离群值为1,离群值为-1。

    • get_params(deep=True)[source]

    • 获取该估计器的参数。

      • Parameters

        • deepbool, default=True

        • 如果为True,将返回这个估计器和包含的子对象的估计器的参数。

      • Returns

        • paramsdict

        • 对应到其值的参数名称。

    • predict(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

        • y_predndarray of shape (n_samples,)

        • X中样本的类标签。

    • score_samples(X)[source]

    • 样本的原始评分功能。

      • Parameters

        • Xarray-like of shape (n_samples, n_features)

        • 数据矩阵。

      • Returns

        • score_samplesndarray of shape (n_samples,)

        • Returns the (unshifted)scoring function of the samples.

    • set_params(**params)[source]

    • 设置该估计器的参数。

      该方法适用于简单的估计器以及嵌套对象(例如 Pipeline )。后者具有 <component>__<parameter> 形式的参数,因此可以更新嵌套对象的每个组件。

      • Parameters

        • **paramsdict

        • 估计器参数:

      • Returns

        • selfestimator instance

        • 估算机实例。

使用 sklearn.svm.OneClassSVM 的示例

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多