简体   繁体   中英

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:

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?

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM