[Fixed] no module named ‘sklearn.cross_validation’

In this post, we will see how to resolve error modulenotfounderror: no module named ‘sklearn.cross_validation’ in Python.
[toc]

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:

from sklearn.cross_validation import train_test_split

It might return you following error:

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:

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.

[social_share share_on="facebook,twitter,linkedin,whatsapp"][post_navigator in_same_term="true"]

Leave a Reply

Your email address will not be published. Required fields are marked *

Subscribe to our newletter

Get quality tutorials to your inbox. Subscribe now.