@[toc]
一、报错代码
from sklearn.grid_search import GridSearchCV
二、报错信息
ModuleNotFoundError Traceback (most recent call last)
Input In [28], in <cell line: 8>()
6 from IPython.display import Image
7 from sklearn.ensemble import RandomForestRegressor
----> 8 from sklearn.grid_search import GridSearchCV
9 # from sklearn.model_selection import GridSearchCV
10 from sklearn.model_selection import train_test_split
ModuleNotFoundError: No module named 'sklearn.grid_search'
三、报错原因
sklearn.grid_search模块在0.18版本中被弃用,它所支持的类转移到model_selection模块中。还要注意,新的CV迭代器的接口与这个模块的接口不同。sklearn.grid_search将在0.20中被删除。
四、解决方案
将报错代码替换为下面的代码即可解决问题:
from sklearn.model_selection import GridSearchCV