开始使用免费开始使用

交叉验证测试的局限

如果您想进行非常大量的交叉验证,可以为 nfoldnum_boost_round 指定非常大的数值。数据框 cv_results_big 已经加载到工作区,并通过以下代码创建:

cv = xgb.cv(params, DTrain, num_boost_round = 600, nfold=10,
            shuffle = True)

这里,cv() 进行了 600 次交叉验证迭代!参数 shuffle 告诉函数每次都打乱记录。

请查看这些数据以了解 AUC 的取值,并检查在交叉验证中它们是否达到 1.0。您还应绘制测试集 AUC 分数的图,观察其随迭代的变化过程。

数据框 cv_results_big 已加载到工作区。

本练习是课程的一部分

Python 信用风险建模

查看课程

练习说明

  • 打印交叉验证结果数据框的前 5 行。
  • 打印交叉验证结果数据框中测试集 AUC 的平均值,并四舍五入到小数点后 2 位。
  • 绘制测试集 AUC 随每次迭代变化的折线图。

交互式实操练习

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

# Print the first five rows of the CV results data frame
print(____.____())

# Calculate the mean of the test AUC scores
print(np.____(____[____]).round(2))

# Plot the test AUC scores for each iteration
plt.____(____[____])
plt.title('Test AUC Score Over 600 Iterations')
plt.xlabel('Iteration Number')
plt.ylabel('Test AUC Score')
plt.____()
编辑并运行代码