gpt4 book ai didi

python - 导入错误 : cannot import name cross_validation

转载 作者:太空狗 更新时间:2023-10-30 01:56:28 25 4
gpt4 key购买 nike

我无法从 sklearn 库中导入 cross_validation;我使用 sklearn 版本 0.20.0

from sklearn import cross_validation

后面的代码:

features_train, features_test, labels_train, labels_test = cross_validation.train_test_split(word_data, authors, test_size=0.1, random_state=42)

错误:

Traceback (most recent call last):
File "D:\me\M.Sc\Udacity_ML_course\ud120-projects- master\naive_bayes\nb_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

最佳答案

发生这种情况是因为 sklearn 中没有 cross_validation 对象。您可能正在寻找更像 cross_validate 函数的东西。您可以通过访问它

from sklearn.model_selection import cross_validate

但是,您不需要导入任何交叉验证软件来执行训练-测试拆分,因为这只会从数据中随机抽样。尝试

from sklearn.model_selection import train_test_split

其次是

features_train, features_test, labels_train, labels_test = train_test_split(word_data, authors, test_size=0.1, random_state=42)

关于python - 导入错误 : cannot import name cross_validation,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53011739/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com