python

时间:2019-07-27 15:50:07

标签: scikit-learn cross-validation xgbclassifier

我正在尝试运行XGBClassifier参数调整,并在此代码行之后出现“'name'cross_validation'not defined”错误:

  kfold_5 =  cross_validation.KFold(n = len(X), shuffle = True, n_folds = numFolds)

也许我没有导入适当的库?

1 个答案:

答案 0 :(得分:1)

首先,获取您的版本:

import sklearn
sklearn.__version__

在scikit-learn版本0.17之后,cross_validation.KFold已迁移到model_selection.KFold

如果您使用的是0.17版本,请使用以下版本:

from sklearn.cross_validation import KFold

kfold_5 = KFold(n= len(X), n_folds = numFolds, shuffle=True)

如果您的版本低于0.17,请使用以下版本:

from sklearn.model_selection import KFold

kfold_5 = KFold(n_splits = numFolds, shuffle=True)

Documentation for 0.21 version is here