在导入GridSearchCV时,0.18.1版本会出现DeprecationWarning警告。

5

我有一个scikit-learn安装版本为0.18.1:

$ pip uninstall -y scipy scikit-learn $ pip install scipy scikit-learn

当我导入GridSearchCV时,会出现奇怪的DeprecationWarning:

(venv2) :~/$ cat warn.pyy
from sklearn.grid_search import GridSearchCV
import sklearn as sk
print(sk.__version__)

如果我运行它,我会得到:
(venv2) :~/$ python warn.py
/home/n/venv2/local/lib/python2.7/site-packages/sklearn/cross_validation.py:44: 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.
  "This module will be removed in 0.20.", DeprecationWarning)
/home/n/venv2/local/lib/python2.7/site-packages/sklearn/grid_search.py:43: 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. This module will be removed in 0.20.
  DeprecationWarning)

0.18.1

如何避免这个弃用警告?
1个回答

9

废弃警告有点误导人。如@abccd所说,GridSearchCV并不会消失,它正在被移动到scikit-learn中的另一个子模块。

替代方案为:

from sklearn.grid_search import GridSearchCV

使用:

from sklearn.model_selection import GridSearchCV

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接