具有 OneClassSVM 错误的详尽网格搜索

Exhaustive Grid search with OneClassSVM error

我正在尝试将 OneClassSVMGridSearchCV 一起使用,如下所示:

param_grid={'nu':[0.0001,0.001,0.01,0.1,1],'gamma':[0.0001,0.001,0.01,0.1,1],'kernel':['rbf','poly','linear']}
svc=svm.OneClassSVM()
model=GridSearchCV(svc,param_grid)

但是命令

model.fit(X_train, y_train)

给我错误:

TypeError: If no scoring is specified, the estimator passed should have a 'score' method. The estimator OneClassSVM(cache_size=200, coef0=0.0, degree=3, gamma='scale', kernel='rbf',
            max_iter=-1, nu=0.5, shrinking=True, tol=0.001, verbose=False) does not.

P.S。使用 SVC 而不是 OneClassSVM 是可行的。

来自 GridSearchCV

的文档

估算器:

This is assumed to implement the scikit-learn estimator interface. Either estimator needs to provide a score function, or scoring must be passed.

还有
得分:

Strategy to evaluate the performance of the cross-validated model on the test set.

您可以在文档页面上阅读更多相关信息。 在您的情况下,您可以使用此处列出的其中一种评分方法 Metrics and scoring

我会首先通过 'accuracy' 只是为了看看它是否解决了问题,然后从那里开始

model = GridSearchCV(svc, param_grid, scoring='accuracy')