9951 explained code solutions for 126 technologies

python-scikit-learnHow to get best estimator from grid search CV

from sklearn import svm, datasets, model_selection

iris = datasets.load_iris()
parameters = {'kernel':('linear', 'rbf'), 'C':[1, 10]}

clf = model_selection.GridSearchCV(svm.SVC(), parameters)
clf.fit(iris.data, iris.target)

estimator = clf.best_estimator_ctrl + c
from sklearn import

import module from scikit-learn


loads Iris dataset


parameters dictionary to run grid search accross


creates GridSearchCV model


use SVC model as an estimator


train transformation model


returns estimator which gave highest score