Ajuste de max_depth
En este ejercicio, tu tarea es ajustar max_depth, el parámetro que determina la profundidad máxima a la que puede crecer cada árbol en una ronda de boosting. Valores más pequeños dan lugar a árboles más poco profundos y valores más grandes a árboles más profundos.
Este ejercicio forma parte del curso
Extreme Gradient Boosting con XGBoost
Instrucciones del ejercicio
- Crea una lista llamada
max_depthspara almacenar los siguientes valores de"max_depth":2,5,10y20. - Itera sobre tu lista
max_depthsusando un buclefor. - Varía de forma sistemática
"max_depth"en cada iteración del buclefory realiza una validación cruzada de 2 particiones con early stopping (5rondas),10rondas de boosting, una métrica"rmse"y unaseedde123. Asegúrate de que la salida sea un DataFrame.
Ejercicio interactivo práctico
Prueba este ejercicio y completa el código de muestra.
# Create your housing DMatrix
housing_dmatrix = xgb.DMatrix(data=X,label=y)
# Create the parameter dictionary
params = {"objective":"reg:squarederror"}
# Create list of max_depth values
max_depths = ____
best_rmse = []
# Systematically vary the max_depth
for curr_val in ____:
params["____"] = ____
# Perform cross-validation
cv_results = ____
# Append the final round rmse to best_rmse
best_rmse.append(cv_results["test-rmse-mean"].tail().values[-1])
# Print the resultant DataFrame
print(pd.DataFrame(list(zip(max_depths, best_rmse)),columns=["max_depth","best_rmse"]))