9951 explained code solutions for 126 technologies

python-scikit-learnHow to get best parameters 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)

params = clf.best_params_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


dictionary with best parameters names and values