Install graphiz on AWS Sagemaker

2020-05-01 08:10发布

问题:

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')
199 
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?

回答1:

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.