在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
————————————————