The sklearn.tree.tree module is deprecated in version 0.22 and will be removed in version 0.24

£可爱£侵袭症+ 提交于 2021-02-11 05:29:49

问题


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: 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.

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)

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

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?


回答1:


  • 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.)

  • 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'
    

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




回答2:


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.



来源:https://stackoverflow.com/questions/60598050/the-sklearn-tree-tree-module-is-deprecated-in-version-0-22-and-will-be-removed-i

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!