Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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'
like image 649
Suresh Mithun Avatar asked Mar 07 '19 13:03

Suresh Mithun


Video Answer


1 Answers

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
like image 51
desertnaut Avatar answered Oct 05 '22 04:10

desertnaut