Home > database >  Exhaustive Grid search with OneClassSMV error
Exhaustive Grid search with OneClassSMV error

Time:11-19

I'm trying to use OneClassSVM with GridSearchCV as follows:

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)

But the command

model.fit(X_train, y_train)

Gives me the error:

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.

Any hints? Thank you very much

P.S. Using SVC instead of OneClassSVM it works.

CodePudding user response:

From the doc of GridSearchCV

estimator :

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

also
scoring :

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

You can read more about it on the documentation page. In your case you may be able to use one of the scoring methods listed here Metrics and scoring

I would start by passing 'accuracy' just to see if it fixes the issue and then take it from there

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