This article was written by Will Koehrsen.
Here’s the complete code: just copy and paste into a Jupyter Notebook or Python script, replace with your data and run:
The final result is a complete decision tree as an image.
random forest for modeling it’s used in this example. (The trees will be slightly different from one another!).
export_graphvizfunction in Scikit-Learn. There are many parameters here that control the look and information displayed. Take a look at the documentation for specifics.
pngusing a system command: running system commands in Python can be handy for carrying out simple tasks. This requires installation of graphviz which includes the dot utility. For the complete options for conversion, take a look at the documentation.
matplotlibto show images).
To read the rest of this article with code and illustrations, click here.