交叉验证评分
现在,请使用 cross_val_score() 进行交叉验证评分,检查整体性能。
这道练习非常适合试用超参数 learning_rate 和 max_depth。请记住,超参数就像模型的设置,可以帮助获得更优的性能。
数据集 cr_loan_prep、X_train 和 y_train 已经加载到工作区。
本练习是课程的一部分
Python 信用风险建模
练习说明
- 使用学习率为
0.1、最大深度为7的梯度提升树,并将模型保存为gbt。 - 使用
4折在X_train和y_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))