objectif
Recherche aléatoire d’hyperparamètres efficace.
code minimal
from sklearn.model_selection import RandomizedSearchCV
from sklearn.ensemble import RandomForestClassifier
from sklearn.datasets import load_iris
import numpy as np
X, y = load_iris(return_X_y=True)
param = {"n_estimators":[10,50,100], "max_depth":[None,3,5]}
rs = RandomizedSearchCV(RandomForestClassifier(random_state=0), param, n_iter=3, random_state=0, cv=3).fit(X, y)
print(isinstance(rs.best_params_, dict))
utilisation
print(rs.best_score_ >= 0.0)
variante(s) utile(s)
from sklearn.model_selection import GridSearchCV
print(hasattr(GridSearchCV(RandomForestClassifier(), {"n_estimators":[10]}), "fit"))
notes
- Échantillonner distributions continues avec scipy.stats.