0

I'm trying to visualize a graph in (Decision Tree). I used sklearn libraries to create the dot file. I use sublime text 3.3.2 as a text Editor .

python version: 3.9.1.

I installed Graphiz from Install package after command+shift+P on mac 10.15.5 MacOS Catalina.

My code:

digraph Tree {
node [shape=box, style="filled, rounded", color="black", fontname=helvetica] ;
edge [fontname=helvetica] ;
0 [label="age <= 24.5\ngini = 0.775\nsamples = 32\nvalue = [8, 10, 5, 5, 4]\nclass = Classical", fillcolor="#f4fdee"] ;
1 [label="gender <= 0.5\ngini = 0.5\nsamples = 10\nvalue = [0, 0, 5, 5, 0]\nclass = Dance", fillcolor="#ffffff"] ;
0 -> 1 [labeldistance=2.5, labelangle=45, headlabel="True"] ;
2 [label="gini = 0.0\nsamples = 5\nvalue = [0, 0, 0, 5, 0]\nclass = HipHop", fillcolor="#3c39e5"] ;
1 -> 2 ;
3 [label="gini = 0.0\nsamples = 5\nvalue = [0, 0, 5, 0, 0]\nclass = Dance", fillcolor="#39e5c5"] ;
1 -> 3 ;
4 [label="gender <= 0.5\ngini = 0.628\nsamples = 22\nvalue = [8, 10, 0, 0, 4]\nclass = Classical", fillcolor="#ecfbe3"] ;
0 -> 4 [labeldistance=2.5, labelangle=-45, headlabel="False"] ;
5 [label="age <= 32.5\ngini = 0.463\nsamples = 11\nvalue = [0, 7, 0, 0, 4]\nclass = Classical", fillcolor="#c6f4aa"] ;
4 -> 5 ;
6 [label="gini = 0.0\nsamples = 4\nvalue = [0, 0, 0, 0, 4]\nclass = Jazz", fillcolor="#e539c0"] ;
5 -> 6 ;
7 [label="gini = 0.0\nsamples = 7\nvalue = [0, 7, 0, 0, 0]\nclass = Classical", fillcolor="#7be539"] ;
5 -> 7 ;
8 [label="age <= 38.5\ngini = 0.397\nsamples = 11\nvalue = [8, 3, 0, 0, 0]\nclass = Accoustic", fillcolor="#efb083"] ;
4 -> 8 ;
9 [label="gini = 0.0\nsamples = 8\nvalue = [8, 0, 0, 0, 0]\nclass = Accoustic", fillcolor="#e58139"] ;
8 -> 9 ;
10 [label="gini = 0.0\nsamples = 3\nvalue = [0, 3, 0, 0, 0]\nclass = Classical", fillcolor="#7be539"] ;
8 -> 10 ;
}

Issue

I can see Graphvizer pluggin on Sublime text from Tools but I can not find graphviz version in my directory /usr/local/ , so i'm not sure if it was installed properly.

The error message from sublime text after command+shift+G is not giving any output result, seems like the command is not even ran.

What I have tried

I also read that I could also use xdot for visualization which I downloaded using pip install.

My goal is to visualize the graph.dot using graphviz, which I installed using pip. I created the graph.dot using jupyter dashboard

I used the Terminal on Pycharm for more precision.

Can somebody help me figure it out ? Thank you very much everyone !

1 Answers1

0

Convert your dot file (say graph.dot), into an image format (say PNG), using the command

dot graph.dot -T png -o graph.png

once you have installed dot.

The dot executable should be installed with the GraphViz package by doing a brew install graphviz.

You can then open the PNG using an image viewer.

Possibly a duplicate of Graphviz: How to go from .dot to a graph?.

Nikhil Kumar
  • 1,015
  • 1
  • 9
  • 14