问题描述
python运行代码时,到from sklearn.grid_search import GridSearchCV时报错:
ModuleNotFoundError: No module named 'sklearn.grid_search'
原因
DeprecationWarning: This module was deprecated in version 0.18 in favor of the model_selection module into which all the refactored classes and functions are moved. Also note that the interface of the new CV iterators are different from that of this module. This module will be removed in 0.20.
意思是说:
sklearn.grid_search模块在0.18版本中被弃用,它所支持的类转移到model_selection模块中。还要注意,新的CV迭代器的接口与这个模块的接口不同。sklearn.grid_search将在0.20中被删除。
解决办法
检查Scikit-Learn的版本conda list scikit-learn
如果高于等于0.20说明是grid_search模块已被弃用。
将from sklearn.grid_search import GridSearchCV
改为from sklearn.model_selection import GridSearchCV