无法从版本> 0.20的sklearn导入cross_validation

时间:2018-11-28 09:19:22

标签: python scikit-learn cross-validation

当我从cross_validation导入sklearn时:

from sklearn import cross_validation

我收到以下错误:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: cannot import name 'cross_validation' from 'sklearn' (/root/anaconda3/lib/python3.7/site-packages/sklearn/__init__.py)

1 个答案:

答案 0 :(得分:3)

您必须将其称为

#if defined(__GNUC__)
#define PRAGMA(x) _Pragma(#x)
#define COMP_MSG(msg)\
PRAGMA(message msg)
#elif defined(__ARMCC_VERSION)
// need code here
#endif

COMP_MSG("WARNING")

如果要进行train test splitting

,则需要提供以下内容
from sklearn.model_selection import cross_validate

sklearn中的交叉验证火车测试拆分已弃用

from sklearn.model_selection import train_test_split
a_train, a_test, b_train, b_test = train_test_split(a, b, 
                                         test_size=0.33, random_state=42)

Deprecated since version 0.18: This module will be removed in 0.20. Use sklearn.model_selection.train_test_split instead