【问题标题】:Why am I getting `[LibSVM]` when im doing outlier detection with OneClassSVM当我使用 OneClassSVM 进行异常值检测时,为什么会得到“[LibSVM]”
【发布时间】:2020-02-23 03:48:51
【问题描述】:

我正在使用 PythonScikit-Learn 库进行异常值检测。我使用OneClassSVM。 我有一个问题,因为当我运行我的代码时(我没有收到错误),它会打印 [LibSVM]

我不知道为什么会这样,我的代码中没有打印功能。

out_cls = [['One class SVM',OneClassSVM(cache_size=80, coef0=0.5, gamma ='auto', kernel = 'poly', random_state= None, shrinking=True, tol = 0.1, verbose = True, nu = 0.2)],          
           ['Isolation Forest', IsolationForest(behaviour='new', contamination='auto',max_features=4, max_samples=2, n_estimators= 90, random_state=1)]]

r = df
for out in out_cls:

    cls = out[1]
    model = cls.fit(x)
    prediction = model.predict(x)

   # print(model.best_params_)

    result = []
    for i in prediction:
        if i == -1:
            result.append('BOT')

        else:
            result.append('good')

    r[out[0]] = result

【问题讨论】:

    标签: python machine-learning scikit-learn libsvm outliers


    【解决方案1】:

    scikit-learn 中的所有底层 SVM 功能实际上都是基于 LibSVM;来自OneClassSVM的文档:

    实现基于 libsvm。

    另请参阅source code 中的大量引用。

    这个控制台输出只是在模型定义中设置verbose=True的产物;改编docs中的简单示例:

    from sklearn.svm import OneClassSVM
    X=[[0], [0.44], [0.45], [0.46], [1]]
    clf = OneClassSVM(gamma='auto', verbose=True)
    clf.fit(X)
    

    显示输出为:

    [LibSVM]
    
    OneClassSVM(cache_size=200, coef0=0.0, degree=3, gamma='auto', kernel='rbf',
                max_iter=-1, nu=0.5, random_state=None, shrinking=True, tol=0.001,
                verbose=True)
    

    设置verbose=False 会消除[LibSVM] 指示,这在任何情况下都不是问题,因为它不会以任何方式影响您的代码。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-06-22
      • 2012-03-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多