1

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?

t_warsop
  • 1,170
  • 2
  • 24
  • 38
  • 1
    a) 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.) b) You could suppress all `FutureWarning`s, but then you might miss another more important one. So I'd just ignore it for now. – smci Mar 09 '20 at 10:27
  • If you want b) to suppress all `FutureWarning`s from sklearn and other packages, [How to suppress Future warning from import?](https://stackoverflow.com/a/15778297/202229), although obviously you replace `import pandas` with your own import statement. – smci Mar 09 '20 at 10:52

2 Answers2

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

desertnaut
  • 57,590
  • 26
  • 140
  • 166
smci
  • 32,567
  • 20
  • 113
  • 146
1

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.

Prasann
  • 701
  • 7
  • 9
  • Prasann, if that's generic issue with sklearn packages, shouldn't we rename it to [The `sklearn.*` module is deprecated in version 0.22 and will be removed in version 0.24](https://stackoverflow.com/questions/59643694/the-sklearn-neighbors-kde-module-is-deprecated-in-version-0-22-and-will-be-remov), then close this into that as a duplicate? – smci Mar 09 '20 at 10:22
  • I saw that answer already. It still doesn't give any information about what needs to be changed. My main issue it that it's saying sklearn.tree.tree is deprecated but I'm not using sklearn.tree.tree anywhere. Is this warning just a red herring that can be ignored? – t_warsop Mar 09 '20 at 10:23
  • 1
    yes, you can ignore it. And you are using sklearn. Tree import DecisionTreeClassifier which is tree. you can refer to this link also. ----https://scikit-learn.org/stable/auto_examples/tree/plot_unveil_tree_structure.html#sphx-glr-auto-examples-tree-plot-unveil-tree-structure-py – Prasann Mar 09 '20 at 10:29