objectif
Gradient boosting rapide par histogrammes.
code minimal
from sklearn.experimental import enable_hist_gradient_boosting # noqa: F401
from sklearn.ensemble import HistGradientBoostingClassifier
from sklearn.datasets import load_breast_cancer
from sklearn.model_selection import train_test_split
X, y = load_breast_cancer(return_X_y=True)
Xtr, Xte, ytr, yte = train_test_split(X, y, random_state=42, stratify=y)
clf = HistGradientBoostingClassifier(max_depth=6, learning_rate=0.1).fit(Xtr, ytr)
print(clf.score(Xte, yte) > 0.5)
utilisation
print(getattr(clf, "feature_importances_", None) is None or True)
variante(s) utile(s)
from sklearn.ensemble import HistGradientBoostingRegressor
print(hasattr(HistGradientBoostingRegressor(), "fit"))
notes
- Gère des NaN en entrée; très performant.