关于python:ImportError:无法从’sklearn’导入名称’cross_validation’

ImportError: cannot import name 'cross_validation' from 'sklearn'

本问题已经有最佳答案,请猛点这里访问。

这是我的密码,请帮忙。我是个初学者。

1
2
3
4
5
6
7
    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

我正在使用最新版本的sklearn,但我收到了这个错误

在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
icha\AppData\Local\Programs\Python\Python37-32\lib\site-packages\sklearn__init__.py)

在Ubuntu上:

Traceback (most recent call last): File"MalwareDetector.py", line 8,
in from sklearn import cross_validation ImportError: cannot
import name cross_validation


从0.18版开始,cross_validation已被弃用。此模块将在0.20中删除。使用sklearn.model_selection.train_test_split代替。

1
from sklearn.model_selection import cross_validate

sklearn 0.19文档