在anaconda 环境下,jupyter中编写监督学习代码,绘制决策树,出现如下错误:
问题: ImportError: cannot import name ‘plot_tree’ 或 module ‘sklearn.tree’ has no attribute ‘plot_tree’
意思就是说,找不到plot_tree函数,经过查阅百度,知道,plot_tree
函数是在 scikit-learn 的 0.21
版本加入的,所以需要 0.21
之后的的版本才能使用这个函数,如果环境中的 scikit-learn 低于这个版本,在导入或调用 plot_tree
函数时自然就会报错了。
接下来,解决办法:
1. 在prompt环境下,命令行模式打开
2. 换源
清华源 官方网址:https://mirror.tuna.tsinghua.edu.cn/help/anaconda/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/
conda config --set show_channel_urls yes
3. 升级
conda install scikit-learn=0.24.2
————————————————