[英]The sklearn.tree.tree module is deprecated in version 0.22 and will be removed in version 0.24
I'm using the DecisionTreeClassifier from scikit-learn ( https://scikit-learn.org/stable/modules/generated/sklearn.tree.DecisionTreeClassifier.html ) and getting the following warning:我正在使用 scikit-learn ( https://scikit-learn.org/stable/modules/generated/sklearn.tree.DecisionTreeClassifier.html ) 中的 DecisionTreeClassifier 并收到以下警告:
FutureWarning: The sklearn.tree.tree module is deprecated in version 0.22 and will be removed in version 0.24. FutureWarning:sklearn.tree.tree 模块在 0.22 版中已弃用,并将在 0.24 版中删除。 The corresponding classes / functions should instead be imported from sklearn.tree.相应的类/函数应该从 sklearn.tree 导入。 Anything that cannot be imported from sklearn.tree is now part of the private API.任何不能从 sklearn.tree 导入的东西现在都是私有 API 的一部分。
I'm a bit confused about why I'm receiving this warning as I'm not using sklearn.tree.tree
anywhere.我对为什么收到此警告感到有些困惑,因为我没有在任何地方使用sklearn.tree.tree
。 I am using sklearn.tree
as the warning suggests but still receive this warning.我正在使用sklearn.tree
作为警告建议,但仍然收到此警告。 In fact I'm using code of the form:事实上,我正在使用以下形式的代码:
from sklearn.tree import DecisionTreeClassifier
tree = DecisionTreeClassifier(<params>)
tree.fit(training_data, training_labels)
As per the example code given in https://scikit-learn.org/stable/modules/generated/sklearn.tree.DecisionTreeClassifier.html but still get this warning.根据https://scikit-learn.org/stable/modules/generated/sklearn.tree.DecisionTreeClassifier.html 中给出的示例代码,但仍然收到此警告。
I've searched the scikit documentation and online and can't find how to update my code inline with the suggestion in the warning.我已经搜索了 scikit 文档和在线,但找不到如何根据警告中的建议内联更新我的代码。 Does anyone know what I need to change to fix the warning?有谁知道我需要更改什么来修复警告?
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.)您可以忽略弃用警告,这只是一个警告(如果您的代码没有引用该子包,我不会担心,sklearn 内部的某个地方可能有一个导入。)
You could suppress all FutureWarnings , but then you might miss another more important one, on sklearn or another package.您可以取消所有 FutureWarnings ,但是您可能会错过另一个更重要的,在 sklearn 或其他包上。 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'
See the doc , or How to suppress Future warning from import?请参阅文档,或如何抑制来自导入的未来警告? , although obviously you replace import pandas
with your own import statement. ,虽然很明显你用你自己的导入语句替换了import pandas
。
link of the same kind of problem 同类问题的链接
It's just a warning, for now -- until you upgrade scikit/sklearn to version 0.24, You need to update your scikit/sklearn version.这只是一个警告,目前 - 在您将 scikit/sklearn 升级到 0.24 版本之前,您需要更新您的 scikit/sklearn 版本。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.