Hyperparameter tuning con Grid SearchCV
Repliqué el algoritmo de random forest usando GridSearchCV para encontrar la mejor combinación de parámetros. El código es:
from sklearn.model_selection import GridSearchCV
rf = RandomForestClassifier()
parametros = {
'n_estimators' : range(4,101),
'criterion' : ['mse', 'mae', 'gini', 'entropy', 'log_loss'],
'max_depth' : range(2,11)
}
rf_grid = GridSearchCV(rf, parametros, cv = 5, scoring='accuracy').fit(X,y)
El mejor modelo tiene las combinaciones:
{'criterion': 'entropy', 'max_depth': 6, 'n_estimators': 22}
Y el accuracy fue de 0.7888549359137594 usando CV.




