简体   繁体   中英

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'

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

model_selection 已经取代了 grid_search 和 cross_validation

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM