7
votes

I have a multiple-label problem. I use OneVsRestClassifier with SVM. Now I want tuning the parameter by GridSearchCV. I tried

GridSearchCV(estimator=OneVsRestClassifier(svm.SVC(probability=True)), param_grid=dict(C=Cs),
                      n_jobs=-1)

It returns various error info.

How to do GridSearchCV with OneVsRestClassifier? Maybe I should do a pipeline? However, it seems the relationship between OneVsRestClassifier with SVM is not as the pipeline function expected.


I also tried the code below. However, I cannot pass the parameter into the svm.SVC.

parameters = {'kernel':('linear', 'rbf'), 'C':[1, 10]}
svr = OneVsRestClassifier(svm.SVC(probability=True))
clf = grid_search.GridSearchCV(svr, parameters)
clf.fit(X_ptrain, y_ptrain)
1

1 Answers

2
votes

You can use estimator to refer to parameters of SVC as shown below:

parameters = {'estimator__kernel':('linear', 'rbf'), 'estimator__C':[1, 10]}
svr = OneVsRestClassifier(svm.SVC(probability=True))
clf = grid_search.GridSearchCV(svr, parameters)
clf.fit(X_ptrain, y_ptrain)