9951 explained code solutions for 126 technologies


python-scikit-learnHow to disable cross validation in 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, cv=[(slice(None), slice(None))])
clf.fit(iris.data, iris.target)ctrl + c
from sklearn import

import module from scikit-learn

load_iris

loads Iris dataset

parameters

parameters dictionary to run grid search accross

.GridSearchCV(

creates GridSearchCV model

svm.SVC()

use SVC model as an estimator

.fit(

train transformation model

[(slice(None), slice(None))]

will disable cross validation


Usage example

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, cv=[(slice(None), slice(None))])
clf.fit(iris.data, iris.target)

print(clf.best_estimator_)
output
SVC(C=1, kernel='linear')