Grid Search

البحث الشبكي

Definition

Trying every possible combination of specified hyperparameter values and choosing the best by cross-validation.

Definition

Grid search exhaustively evaluates every combination of specified hyperparameter values, typically with cross-validation, and selects the best.

Practical examples

Code example Python
from sklearn.datasets import load_iris
from sklearn.model_selection import GridSearchCV
from sklearn.neighbors import KNeighborsClassifier

X, y = load_iris(return_X_y=True)
gs = GridSearchCV(KNeighborsClassifier(), {'n_neighbors': [1, 3, 5]}, cv=5).fit(X, y)
print(gs.best_params_)

Expected output

{'n_neighbors': 5}

Learn and review

Suggested terms to learn next