【问题标题】:python machine learning DeprecationWarningpython机器学习弃用警告
【发布时间】:2017-12-14 00:32:58
【问题描述】:

你能帮我解决这个问题吗?

C:\Python27\lib\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)

【问题讨论】:

  • post text, not screenshots,即使你方便:)
  • 谢谢,这是我无法解决的问题 C:\Python27\lib\site-packages\sklearn\cross_validation.py:44: DeprecationWarning: This module was deprecated in version 0.18支持将所有重构的类和函数移入的 model_selection 模块。另请注意,新的 CV 迭代器的接口与此模块的接口不同。此模块将在 0.20 中删除。 "这个模块将在 0.20 中被移除。", DeprecationWarning)

标签: machine-learning scipy scikit-learn scikits


【解决方案1】:
现在已弃用Cross_Validation,而是使用Model_Selection,但是所有方法和类都保持不变。您现在只需导入:
from sklearn import model_selection

以及培训和测试您必须执行这样的数据的数据:

x_train,x_test,y_train,y_test=model_selection.train_test_split(x,y,test_size=0.2)

【讨论】:

    【解决方案2】:

    C:\Python27\lib\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 is different from that of this module. This module will be removed in 0.20. "This module will be removed in 0.20.", DeprecationWarning)

    只是一个弃用警告


    不用担心,但请记住 cross_val 将在 0.20 中删除。

    此错误只是警告您开发人员将在执行此功能之前移动此功能。


    只是一个例子。将来我们将不得不替换:

    from sklearn.cross_validation import KFold
    

    与:

     from sklearn.model_selection import KFold
    

    对于我在您发布的屏幕截图中看到的第二个错误SA3L module 似乎没有安装。

    【讨论】:

    • 谢谢 #Sera 是的,我知道这是警告,我使用了 warnings.filterwarnings("ignore") 但它仍然可用,但无论如何谢谢我会忽略它,是的,关于我的错误,我想我没有导入这个类谢谢
    • @javac 没问题。如果这有帮助,请将其标记为已接受的答案。另外,我在答案中添加了一个简单的示例
    • 即使我尝试了这个 import warnings def fxn(): warnings.warn("deprecated", DeprecationWarning) with warnings.catch_warnings(): warnings.simplefilter("ignore") fxn() 仍然可用
    • @javac 不要试图抑制警告。 1)还不错 2)有人应该知道这种弃用。但如果你仍然想要:尝试:import warnings warnings.filterwarnings("ignore", category=DeprecationWarning)
    • @javac 还要确保随着包名的变化,类的内部结构也发生了变化。我的意思是在cross_validation 中工作的KFold 可能在model_selection 中不起作用,或者属性和函数名称也发生了变化。请务必查阅使用文档。
    猜你喜欢
    • 2017-01-01
    • 2021-02-15
    • 2017-03-03
    • 2019-05-14
    • 2017-08-22
    • 2016-09-30
    • 2019-12-29
    • 2016-05-28
    • 2022-10-17
    相关资源
    最近更新 更多