Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to install graphviz in Ubuntu 15 to plot a decision tree for XGBoost?

Tags:

python

xgboost

I want to plot the decision tree of XGBoost. I followed the instructions from this webpage. I get this error:

 ImportError: You must install graphviz to plot tree

I tried to install graphviz_2.38.0-1~saucy_amd64.deb from graphviz. But I get this error:

 *Dependency is not satisfiable:libgraphviz4(>=2.18)*

So I did what is on this link

As it still does not work I downloaded the source code: graphviz-2.40.1.tar.gz But it still does not work. I thought that maybe I have installed it in the wrong path. So what does this mean: Make sure that the directory containing the dot executable is on your systems’ path?

I have installed it in /etc.

I use a virtual environment in conda

Any suggestions on what am I doing wrong?

EDIT:

I used pip install graphviz. now I get this error:

CalledProcessError: Command '['dot', '-Tpng']' returned non-zero exit status 1

Any idea?

like image 532
Aizzaac Avatar asked May 10 '17 15:05

Aizzaac


People also ask

How do you visualize a decision tree in python without graphviz?

The scikit-learn (sklearn) library added a new function that allows us to plot the decision tree without GraphViz. So we can use the plot_tree function with the matplotlib library. If you are new to Python, Just into Data is now offering a FREE Python crash course: breaking into data science!

Where is graphviz installed Ubuntu?

Graphviz is a standard package on many linux distributions. You can check if it is installed with a command like dpkg -s graphivz . If it is not installed, you should be able to install it with your system's package manager. i.e. sudo apt-get install graphviz or search 'graphivz' in the Software Center on Ubuntu.


1 Answers

As per this answer, you will need to install two conda packages:

  • graphviz, which only installs the graphviz system binaries.
  • python-graphviz, which installs the Python package for interfacing with graphviz.

So, install both packages with

conda install graphviz python-graphviz

and you should be ready to go.

like image 91
albarji Avatar answered Sep 28 '22 19:09

albarji