我想在我的模型上实现 KFold 交叉验证。由于我想与他人分享我的结果,我希望每次都有固定的结果。我使用 xgboost 模型作为我的分类模型。但是,每次我运行我的代码时,我的性能指标每次都会给出不同的结果,我很困惑,因为我将shuffle
参数设置为False
. 此外,我不确定该random_state
参数的作用(我阅读了文档),但无论我尝试使用 shuffle=False 将其设置为固定数字,但这并没有帮助。
kf = KFold(n_splits=5, shuffle = False)
for train_index, test_index in kf.split(X, y):
X_train, X_test = X.iloc[train_index], X.iloc[test_index]
y_train, y_test = y.iloc[train_index], y.iloc[test_index]
xgb = XGBClassifier(max_depth = 4)
...fit, predict, and compute performance metrics