Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error: Format: "svg" not recognized. Use one of:

Hallo I try to create a decisiontree with my csv datasheet. I installed in anaconda and python the graphviz package with the following command:

conda install graphviz
pip install graphviz

to get my tree visible. Here is my code that I have wrote in Jupyther Notebook:

import pandas as pd
import graphviz
from sklearn import metrics 
from sklearn.tree import DecisionTreeClassifier, export_graphviz
from sklearn.model_selection import train_test_split

file = 'automotive_data.csv'  
COLS = np.arange(0,22,1).tolist()#gibt später bei usecols eine andere möglichkeit die spalten anzusprechen  
data = pd.read_csv(file, header=0, sep = ",", index_col=0, usecols=COLS)
 

x = data.iloc[:,1:]
x = x.to_numpy()

y = data[['Ausfall']]
y

xTrain, xTest, yTrain, yTest = train_test_split(x, y, test_size=0.3, random_state=1)
model = DecisionTreeClassifier (  
      criterion='entropy',   
      splitter='best',       
      min_samples_split= 0.3,   
      max_features=10,  
      max_depth=None
      )
#Danach mit fit erstellt
model.fit(xTrain, yTrain)

dot=export_graphviz(model, out_file=None,filled=True,  
                            feature_names=data.columns[1:24],   
                            class_names=['ja','nein']);  
 # Erzeuge Graphviz-Graphen aus dot-Quellcode  
graph = graphviz.Source(dot)
graph#Here I get an error

In the last row I get the error:

Format: "svg" not recognized. Use one of:
CalledProcessError                        Traceback (most recent call last)
~\anaconda3\lib\site-packages\IPython\core\formatters.py in __call__(self, obj)
    343             method = get_real_method(obj, self.print_method)
    344             if method is not None:
--> 345                 return method()
    346             return None
    347         else:

~\anaconda3\lib\site-packages\graphviz\files.py in _repr_svg_(self)
    111 
    112     def _repr_svg_(self):
--> 113         return self.pipe(format='svg').decode(self._encoding)
    114 
    115     def pipe(self, format=None, renderer=None, formatter=None, quiet=False):

~\anaconda3\lib\site-packages\graphviz\files.py in pipe(self, format, renderer, formatter, quiet)
    136         out = backend.pipe(self._engine, format, data,
    137                            renderer=renderer, formatter=formatter,
--> 138                            quiet=quiet)
    139 
    140         return out

~\anaconda3\lib\site-packages\graphviz\backend.py in pipe(engine, format, data, renderer, formatter, quiet)
    242     """
    243     cmd, _ = command(engine, format, None, renderer, formatter)
--> 244     out, _ = run(cmd, input=data, capture_output=True, check=True, quiet=quiet)
    245     return out
    246 

~\anaconda3\lib\site-packages\graphviz\backend.py in run(cmd, input, capture_output, check, encoding, quiet, **kwargs)
    182     if check and proc.returncode:
    183         raise CalledProcessError(proc.returncode, cmd,
--> 184                                  output=out, stderr=err)
    185 
    186     return out, err

CalledProcessError: Command '['dot', '-Tsvg']' returned non-zero exit status 1. [stderr: b'Format: "svg" not recognized. Use one of:\r\n']

I also tried to use PNG as my format but it didn't work too. I have no idea how to solve this problem.

like image 867
Razielruss Avatar asked Jul 07 '20 06:07

Razielruss


1 Answers

So apparently the issue is you have to configure the graphviz plugins first.

Open a terminal in administrator mode and run dot -c. (This assumes that the graphviz binaries are in your path)

like image 100
Dalupus Avatar answered Nov 01 '22 19:11

Dalupus