Búsqueda aleatoria con XGBoost
A menudo, GridSearchCV puede llevar mucho tiempo, así que en la práctica quizá prefieras usar RandomizedSearchCV, como harás en este ejercicio. La buena noticia es que solo tienes que hacer unas pocas modificaciones a tu código de GridSearchCV para usar RandomizedSearchCV. La diferencia clave es que debes indicar un parámetro param_distributions en lugar de param_grid.
Este ejercicio forma parte del curso
Extreme Gradient Boosting con XGBoost
Instrucciones del ejercicio
- Crea una rejilla de parámetros llamada
gbm_param_gridque contenga una lista con un único valor para'n_estimators'(25), y una lista de valores de'max_depth'entre2y11; usarange(2, 12)para ello. - Crea un objeto
RandomizedSearchCVllamadorandomized_mse, pasando: la rejilla de parámetros enparam_distributions, elXGBRegressorenestimator,"neg_mean_squared_error"enscoring,5enn_itery4encv. Especifica tambiénverbose=1para entender mejor la salida. - Ajusta el objeto
RandomizedSearchCVaXyy.
Ejercicio interactivo práctico
Prueba este ejercicio y completa el código de muestra.
# Create the parameter grid: gbm_param_grid
gbm_param_grid = {
'____': [____],
'____': ____(____, ____)
}
# Instantiate the regressor: gbm
gbm = xgb.XGBRegressor(n_estimators=10)
# Perform random search: grid_mse
randomized_mse = ____
# Fit randomized_mse to the data
____
# Print the best parameters and lowest RMSE
print("Best parameters found: ", randomized_mse.best_params_)
print("Lowest RMSE found: ", np.sqrt(np.abs(randomized_mse.best_score_)))