ImportError: cannot import name cross_validation
我无法从sklearn库导入交叉验证;我使用sklearn版本0.20.0
1 | from sklearn import cross_validation |
代码后面部分:
1 | features_train, features_test, labels_train, labels_test = cross_validation.train_test_split(word_data, authors, test_size=0.1, random_state=42) |
号
错误:
1 2 3 4 5 6 7 8 | Traceback (most recent call last): File"D:\me\M.Sc\Udacity_ML_course\ud120-projects- master aive_bayes b_author_id.py", line 16, in <module> from email_preprocess import preprocess File"../tools/email_preprocess.py", line 8, in <module> from sklearn import cross_validation ImportError: cannot import name cross_validation |
如果您要查找代码所示的
1 2 3 4 | from sklearn import model_selection features_train, features_test, labels_train, labels_test = model_selection.train_test_split( word_data, authors, test_size=0.1, random_state=42) |
>看起来这在0.18中发生了变化。
这是因为
1 | from sklearn.model_selection import cross_validate |
号
但是,您不需要导入任何交叉验证软件来执行列车测试分割,因为这只是从数据中随机抽样。尝试
1 | from sklearn.model_selection import train_test_split |
然后
1 | features_train, features_test, labels_train, labels_test = train_test_split(word_data, authors, test_size=0.1, random_state=42) |
。