开始使用免费开始使用

调优 eta

现在是系统练习调优其他 XGBoost 超参数并观察其对模型性能影响的时候了!您将从调优 "eta"(也称为学习率)开始。

在 XGBoost 中,学习率是一个介于 01 之间的参数。"eta" 值越高,对特征权重的惩罚越强,正则化也就越强。

本练习是课程的一部分

使用 XGBoost 的极端梯度提升

查看课程

练习说明

  • 创建一个名为 eta_vals 的列表,存储以下 "eta" 值:0.0010.010.1
  • 使用 for 循环遍历 eta_vals 列表。
  • for 循环的每次迭代中,将 params"eta" 键设置为 curr_val。然后执行 3 折交叉验证,包含提前停止(5 轮)、10 轮 boosting,评估指标为 "rmse",并将 seed 设为 123。请确保输出为 DataFrame。
  • 将最终一轮的 RMSE 追加到 best_rmse 列表中。

交互式实操练习

通过完成这段示例代码来试试这个练习。

# Create your housing DMatrix: housing_dmatrix
housing_dmatrix = xgb.DMatrix(data=X, label=y)

# Create the parameter dictionary for each tree (boosting round)
params = {"objective":"reg:squarederror", "max_depth":3}

# Create list of eta values and empty list to store final round rmse per xgboost model
____ = [____, ____, ____]
best_rmse = []

# Systematically vary the eta 
for curr_val in ____:

    params["___"] = curr_val
    
    # Perform cross-validation: cv_results
    cv_results = ____
    
    
    
    # Append the final round rmse to best_rmse
    ____.____(____["____"].tail().values[-1])

# Print the resultant DataFrame
print(pd.DataFrame(list(zip(eta_vals, best_rmse)), columns=["eta","best_rmse"]))
编辑并运行代码