Error: Format: “svg” not recognized. Use one of:

余生颓废 提交于 2020-11-29 04:56:10

问题


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.


回答1:


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)




回答2:


I had the same problem, I solved it by installing version 2.38 instead of 2.44 https://www2.graphviz.org/Packages/stable/windows/10/msbuild/Release/Win32/



来源:https://stackoverflow.com/questions/62769161/error-format-svg-not-recognized-use-one-of

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!