This article is suitable for solving the following few problems:
- module ‘sklearn.tree’ has no attribute ‘plot_tree’
- pip install (on Spyder, Anaconda Prompt, etc.) does not install the latest package.
The leading reason for “module ‘sklearn.tree’ has no attribute ‘plot_tree” is because the sklearn package is outdated.
Sometimes “pip install scikit-learn” simply does not update the sklearn package to the latest version. Type “print(sklearn.__version__)” to get the version of sklearn on your machine, it should be at least 0.21.
The solution is to force pip to install the latest package:
pip install --no-cache-dir --upgrade <package>
In this case, we would replace <package> by “scikit-learn”.
Sometimes, pip install does not work in the Spyder IPython console, it displays an error to the effect that you should install “outside the IPython console”. This is not normal (i.e. it should not happen), but as a quick fix you can try “pip install” in Anaconda Prompt instead. It is likely that something wrong went on during the installation of Anaconda, Python, and the long-term solution is to reinstall Anaconda.