scikit-learn 1 · Evaluation and tuning
Tune hyperparameters
Try every combination of settings with cross-validation and keep the best.
from sklearn.model_selection import GridSearchCV
search = GridSearchCV(RandomForestClassifier(random_state=42),
{"n_estimators": [50, 100], "max_depth": [3, None]}, cv=3)
search.fit(X_train, y_train)
print(search.best_params_, search.best_score_)
Official scikit-learn 1 documentation
More evaluation and tuning commands
- Measure accuracy
- Get precision, recall and F1
- See where the model is wrong
- Evaluate a regression model
- Cross-validate
- See which features matter
All evaluation and tuning commands · scikit-learn 1 cheatsheet