1. Load OneVsRestClassifier within a pipeline:
from sklearn.svm import SVCfrom sklearn.pipeline import Pipelinefrom sklearn.preprocessing import StandardScalerfrom sklearn.multiclass import OneVsRestClassifiersvm_est = Pipeline([('scaler',StandardScaler()),('svc',OneVsRestClassifier(SVC()))])
  1. Set up a parameter grid:
Cs = [0.001, 0.01, 0.1, 1, 10]gammas = [0.001, 0.01, 0.1, 1, 10]
  1. Construct the parameter grid. Note the very special syntax to denote the OneVsRestClassifier SVC. The parameter key names within the dictionary start with svc__estimator__ when named svc within the pipeline:
param_grid = dict(svc__estimator__gamma=gammas, svc__estimator__C=Cs)
  1. Load a randomized hyperparameter search. Fit it:
from sklearn.model_selection ...

Get scikit-learn Cookbook - Second Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.