In this post, we will see how to resolve error modulenotfounderror: no module named ‘sklearn.cross_validation’ in Python.
Table of Contents
Problem: no module named ‘sklearn.cross_validation’
You might get this error even through you have installed scikit-learn
correctly on anaconda.
You might get this error in following scneario:
1 2 3 |
from sklearn.cross_validation import train_test_split |
It might return you following error:
1 2 3 |
ImportError: No module named sklearn.cross_validation |
Solution: Replace cross_validation with model_selection
This error may be related to renaming and deprecation of cross_validation
sub-module to model_selection
.
cross_validation
was deprecated in version 0.18 and was changed to model_selection
from version 0.20 onwards.
You should import model_selection
rather than cross_validation
as below:
1 2 3 |
from sklearn.model_selection import train_test_split |
You can refer documents over here: https://scikit-learn.org/stable/modules/cross_validation.html
It should resolve this issue. Please comment in case this solution does not resolve no module named sklearn.cross_validation
issue.
That’s all about how to resolve no module named sklearn.cross_validation
error in python.