在 AWS Sagemaker 上安装 graphiz

Install graphiz on AWS Sagemaker

我在 Jupyter notebook 上使用 Python3 并尝试使用如下代码绘制一棵树:

import xgboost as xgb
from xgboost import plot_tree

plot_tree(model, num_trees=4)

在最后一行我得到:

~/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

如何安装 graphviz 才能看到 plot_tree?

我终于知道Conda有一个包可以帮你安装。我能够通过 运行 命令安装它:

!conda install python-graphviz --yes

请注意,仅当安装需要验证 adding/changing 其他包时才需要 --yes,因为 Jupyter notebook 在 运行.

后就无法交互