After training a decision tree classifier using Scikit-learn library, we can also visualize the tree structure by using the export_graphviz
function from the sklearn.tree
module. Here's an example:
main.py1043 chars30 lines
This will create a tree.dot
file in the current directory which can be converted to an image using dot
command line tool provided by Graphviz. Alternatively, using pydotplus
and IPython.display
module, you can display the decision tree directly in the notebook. Note that for this to work, you'll need to install Graphviz and pydotplus libraries.
gistlibby LogSnag