sklearn.tree.tree 模块在 0.22 版中已弃用,并将在 0.24 版中删除 [英] The sklearn.tree.tree module is deprecated in version 0.22 and will be removed in version 0.24

查看:72
本文介绍了sklearn.tree.tree 模块在 0.22 版中已弃用,并将在 0.24 版中删除的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 scikit-learn 的 DecisionTreeClassifier (https://scikit-learn.org/stable/modules/generated/sklearn.tree.DecisionTreeClassifier.html)并收到以下警告:

I'm using the DecisionTreeClassifier from scikit-learn (https://scikit-learn.org/stable/modules/generated/sklearn.tree.DecisionTreeClassifier.html) and getting the following warning:

FutureWarning:sklearn.tree.tree 模块在版本中已弃用0.22 并将在 0.24 版本中删除.相应的类/函数应该从 sklearn.tree 导入.任何无法从 sklearn 导入.tree 现在是私有 API 的一部分.

FutureWarning: The sklearn.tree.tree module is deprecated in version 0.22 and will be removed in version 0.24. The corresponding classes / functions should instead be imported from sklearn.tree. Anything that cannot be imported from sklearn.tree is now part of the private API.

我对为什么会收到此警告感到有些困惑,因为我没有在任何地方使用 sklearn.tree.tree.我正在使用 sklearn.tree 作为警告建议,但仍然收到此警告.事实上,我正在使用以下形式的代码:

I'm a bit confused about why I'm receiving this warning as I'm not using sklearn.tree.tree anywhere. I am using sklearn.tree as the warning suggests but still receive this warning. In fact I'm using code of the form:

from sklearn.tree import DecisionTreeClassifier
tree = DecisionTreeClassifier(<params>)
tree.fit(training_data, training_labels)

根据 https://scikit-learn.org/stable/modules/generated/sklearn.tree.DecisionTreeClassifier.html 但仍然收到此警告.

As per the example code given in https://scikit-learn.org/stable/modules/generated/sklearn.tree.DecisionTreeClassifier.html but still get this warning.

我已经搜索了 scikit 文档和在线,但找不到如何根据警告中的建议更新我的代码.有谁知道我需要更改什么来修复警告?

I've searched the scikit documentation and online and can't find how to update my code inline with the suggestion in the warning. Does anyone know what I need to change to fix the warning?

推荐答案

  • 您可以忽略弃用警告,这只是一个警告(如果您的代码没有引用该子包,我不会担心,sklearn 内部的某个地方可能有一个导入.)

    • You can ignore the deprecation warning, it's only a warning (I wouldn't worry if your code isn't referencing that subpackage, there's probably an import somewhere under the hood inside sklearn.)

      您可以取消所有 FutureWarnings,但是您可能会错过另一个更重要的,在 sklearn 或其他软件包上.所以我暂时忽略它.但如果你想:

      You could suppress all FutureWarnings, but then you might miss another more important one, on sklearn or another package. So I'd just ignore it for now. But if you want to:

      import warnings
      warnings.simplefilter('ignore', FutureWarning)
      
      from sklearn.tree import ...
      
      # ... Then turn warnings back on for other packages
      warnings.filterwarnings('module') # or 'once', or 'always'
      

    • 请参阅doc,或如何抑制来自导入的未来警告?,尽管显然您用自己的导入语句替换了 import pandas.

      See the doc, or How to suppress Future warning from import?, although obviously you replace import pandas with your own import statement.

      这篇关于sklearn.tree.tree 模块在 0.22 版中已弃用,并将在 0.24 版中删除的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆