I'm on a Jupyter notebook using Python3 and trying to plot a tree with code like this:

import xgboost as xgb
from xgboost import plot_tree

plot_tree(model, num_trees=4)

On the last line I get:

~/anaconda3/envs/python3/lib/python3.6/site-packages/xgboost/plotting.py in to_graphviz(booster, fmap, num_trees, rankdir, yes_color, no_color, **kwargs)
196         from graphviz import Digraph
197     except ImportError:
--> 198         raise ImportError('You must install graphviz to plot tree')
200     if not isinstance(booster, (Booster, XGBModel)):

ImportError: You must install graphviz to plot tree

How do I install graphviz so I can see the plot_tree?

migrated from datascience.stackexchange.com Mar 12 at 0:46

This question came from our site for Data science professionals, Machine Learning specialists, and those interested in learning more about the field.


I was finally able to learn that Conda has a package which can install it for you. I was able to get it installed by running the command:

!conda install python-graphviz --yes

Note the --yes is only needed if the installation needs to verify adding/changing other packages since the Jupyter notebook is not interactive once it is running.

Your Answer

By clicking "Post Your Answer", you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.