本文介绍了在 AWS Sagemaker 上安装 graphiz的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在使用 Python3 的 Jupyter 笔记本上并尝试使用如下代码绘制树:

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)

在最后一行我得到:

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

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

推荐答案

我终于知道 Conda 有一个可以为你安装的包.我可以通过运行以下命令安装它:

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

注意 --yes 仅在安装需要验证添加/更改其他包时才需要,因为 Jupyter 笔记本一旦运行就不是交互式的.

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.

这篇关于在 AWS Sagemaker 上安装 graphiz的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-13 19:10