Modulenotfounderror: No Module Named 'Sklearn. Grid_Search'

I am doing an image detection problem but, I got some errors while I import RandomizedSearchCV.

I have installed:

pip3 install scikit-learn
pip3 install scikit-image

I tried this code first:

from sklearn.neighbors import KNeighborsClassifier
from sklearn.model_selection import GridSearchCV

its worked, After that, I import RandomizedSearchCV like this, and its showing error.

from sklearn.grid_search import RandomizedSearchCV
from sklearn.grid_search import GridSearchCV
from sklaern.cross_validation import train_test_split


---------------------------------------------------------------------------
ModuleNotFoundError                       Traceback (most recent call last)
<ipython-input-11-9f5ecfd22091> in <module>
----> 1 from sklearn.grid_search import RandomizedSearchCV
      2 from sklearn.grid_search import GridSearchCV
      3 from sklaern.cross_validation import train_test_split

ModuleNotFoundError: No module named 'sklearn.grid_search'

 >>> import sklearn
>>> sklearn.__version__
'0.20.3'
0

1 Answer

In recent versions, these modules are now under sklearn.model_selection, and not any more under sklearn.grid_search, and the same holds true for train_test_split (docs); so, you should change your imports to:

from sklearn.model_selection import RandomizedSearchCV
from sklearn.model_selection import GridSearchCV
from sklearn.model_selection import train_test_split

or more concisely

from sklearn.model_selection import RandomizedSearchCV, GridSearchCV, train_test_split

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Marcus Vance

Marcus Vance

Cybersecurity & Digital Privacy Researcher

Marcus Vance is a cybersecurity auditor and technology writer dedicated to educating the public about online safety, data privacy regulations, enterprise security, and emerging cyber threats.

Share this article
Twitter Facebook Pinterest