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

Viewed 91903

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

On 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)

On Ubuntu:

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

1 Answers

cross_validation is deprecated since version 0.18. This module will be removed in 0.20.

Use sklearn.model_selection.train_test_split instead.

from sklearn.model_selection import train_test_split

More: sklearn 0.19 docs

Related