top of page

Random Forest

  • niko
  • 3 sept. 2018
  • 1 min de lecture

CODE PYTHON:

from sklearn.ensemble import RandomForestClassifier

from sklearn.model_selection import GridSearchCV

#DATAS from sklearn.datasets import load_digits digits = load_digits() X, y = digits.data, digits.target

## mise à l'échelle : normalisation from sklearn.preprocessing import StandardScaler scaler = StandardScaler() X_std = scaler.fit_transform(X)

#stratégie de cross-validation

cv = ShuffleSplit(n_splits=30, test_size=0.2)

#initialisation du classifieur

clf_forest = RandomForestClassifier()

n_arbres_grid = [1, 5, 10, 20, 50, 100] parameters = {'n_estimators': n_arbres_grid}

clf_forest_grid = GridSearchCV(clf_forest, parameters, cv=cv) clf_forest_grid.fit(X_std, y)

plt.plot(n_arbres_grid, clf_forest_grid.cv_results_['mean_test_score']) print('Meilleure valeur du paramètre: ', clf_forest_grid.best_params_)

Commentaires


A découvrir ...
bottom of page