Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OneVsRestClassification with GridSearchCV in Sklearn

When I tried to search the optimal C and gamma in rbf kernel SVM by:

params = dict(C = C_range, gamma = gamma_range)
clf = GridSearchCV(OneVsRestClassifier(SVC()),params, cv = 5)

It returns the error says C is not the parameter of OneVsRestClassifier. What is the proper way to achieve the grid search on the parameters with multiclass SVM then?

like image 530
ChuNan Avatar asked Oct 01 '22 03:10

ChuNan


1 Answers

Grid search uses a custom nested attribute syntax for this:

params = dict(estimator__C=C_range, estimator__gamma=gamma_range)

The name estimator corresponds to the OneVsRestClassifier constructor parameter. Note the double underscores.

like image 160
Fred Foo Avatar answered Oct 13 '22 12:10

Fred Foo