Python 导入错误:无法从“sklearn”导入名称“cross_validation”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/53978901/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
ImportError: cannot import name 'cross_validation' from 'sklearn'
提问by Richard Phillips Roy
Here is my code Please Help. I'm a beginner.
这是我的代码请帮助。我是初学者。
import pandas as pd
import sklearn
from sklearn.feature_selection import SelectFromModel
from sklearn.ensemble import ExtraTreesClassifier
from sklearn.metrics import confusion_matrix
from sklearn.model_selection import train_test_split
from sklearn import cross_validation
I'm using the latest version of Sklearn but I'm getting this error
我正在使用最新版本的 Sklearn,但出现此错误
On Windows:
在 Windows 上:
Traceback (most recent call last): File "MalwareDetector.py", line 8, in from sklearn import cross_val_score ImportError: cannot import name 'cross_val_score' from 'sklearn' (C:\Users\richa\AppData\Local\Programs\Python\Python37-32\lib\site-packages\sklearn__init__.py)
回溯(最近一次调用):文件“MalwareDetector.py”,第 8 行,在 from sklearn import cross_val_score ImportError: cannot import name 'cross_val_score' from 'sklearn' (C:\Users\richa\AppData\Local\Programs\Python \Python37-32\lib\site-packages\sklearn__init__.py)
On Ubuntu:
在 Ubuntu 上:
Traceback (most recent call last): File "MalwareDetector.py", line 8, in from sklearn import cross_validation ImportError: cannot import name cross_validation
回溯(最近一次调用):文件“MalwareDetector.py”,第 8 行,来自 sklearn 导入 cross_validation 导入错误:无法导入名称 cross_validation
回答by Eder
cross_validation
is deprecated since version 0.18. This module will be removed in 0.20. Use sklearn.model_selection.train_test_split instead.
cross_validation
自 0.18 版起已弃用。此模块将在 0.20 中删除。改用 sklearn.model_selection.train_test_split 。
from sklearn.model_selection import cross_validate