【问题标题】:How to use GridSearchCV for one-class classification如何使用 GridSearchCV 进行一类分类
【发布时间】:2019-09-22 04:30:11
【问题描述】:

我尝试使用 GridSearchCV 以便为我的分类器提供最佳参数。我用的是一类SVM,我的代码是:

tuned_parameters = [{'kernel': ['rbf'], 'gamma': [1e-2, 1e-3, 1e-4, 1e-5],
                 'nu': [0.001, 0.10, 0.1, 10, 25, 50, 100, 1000]},
                {'kernel': ['linear'], 'nu': [0.001, 0.10, 0.1, 10, 25, 50, 100, 1000]}
               ] 

scores = ['precision', 'recall']

for score in scores:
  print("# Tuning hyper-parameters for %s" % score)
  print()

 clf = GridSearchCV(svm.OneClassSVM(), tuned_parameters,
                   scoring='%s_macro' % score)
 clf.fit(input_dataN)

我遇到了错误:

TypeError: __call__() missing 1 required positional argument: 'y_true'

请问如何解决?

【问题讨论】:

    标签: scikit-learn svm gridsearchcv


    【解决方案1】:

    当您应用拟合方法时,您需要提供特征 (X_train) 以及目标类标签 (y_train):

    修正这一行:

    clf.fit(input_dataN)
    

    【讨论】:

    • 我用的是一类分类,我没有y_train。
    • 如果您只有正面标签,那么您可以做的事情就会受到限制。 this link might be useful
    猜你喜欢
    • 2016-09-26
    • 2014-04-07
    • 2012-04-02
    • 2021-02-17
    • 1970-01-01
    • 2022-01-27
    • 2019-12-10
    • 2017-03-29
    相关资源
    最近更新 更多