开始使用免费开始使用

交叉验证评分

现在,请使用 cross_val_score() 进行交叉验证评分,检查整体性能。

这道练习非常适合试用超参数 learning_ratemax_depth。请记住,超参数就像模型的设置,可以帮助获得更优的性能。

数据集 cr_loan_prepX_trainy_train 已经加载到工作区。

本练习是课程的一部分

Python 信用风险建模

查看课程

练习说明

  • 使用学习率为 0.1、最大深度为 7 的梯度提升树,并将模型保存为 gbt
  • 使用 4 折在 X_trainy_train 上计算交叉验证得分,并将结果保存为 cv_scores
  • 打印交叉验证得分。
  • 以格式化方式打印平均准确率和标准差。

交互式实操练习

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

# Create a gradient boosted tree model using two hyperparameters
____ = xgb.____(____ = ____, ____ = ____)

# Calculate the cross validation scores for 4 folds
____ = ____(____, ____, np.ravel(____), cv = ____)

# Print the cross validation scores
print(____)

# Print the average accuracy and standard deviation of the scores
print("Average accuracy: %0.2f (+/- %0.2f)" % (____.____(),
                                              ____.____() * 2))
编辑并运行代码