pythonadvanced

Grid Search

Data science technique: grid-search

python
from sklearn.model_selection import GridSearchCV
from sklearn.ensemble import RandomForestClassifier
from sklearn.datasets import load_iris

X, y = load_iris(return_X_y=True)
search = GridSearchCV(
    RandomForestClassifier(random_state=42),
    param_grid={"n_estimators": [50, 100], "max_depth": [3, None]},
    cv=5,
)
search.fit(X, y)
print(search.best_params_)
print(round(search.best_score_, 4))

Use Cases

  • machine learning
  • data analysis

Tags

Related Snippets

Similar patterns you can reuse in the same workflow.