gpt4 book ai didi

python-3.x - 错误: Format: "svg" not recognized.使用以下之一:

转载 作者:行者123 更新时间:2023-12-03 15:58:38 25 4
gpt4 key购买 nike

你好,我尝试用csv数据表创建一个决策树。我使用以下命令在anaconda和python中安装了graphviz软件包:

conda install graphviz
pip install graphviz
使我的树可见。这是我在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
在最后一行中,我得到了错误:
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']
我也尝试使用PNG作为我的格式,但是它也不起作用。我不知道如何解决这个问题。

最佳答案

因此,显然问题是必须首先配置graphviz插件。
在管理员模式下打开终端,然后运行dot -c。 (这假设graphviz二进制文件在您的路径中)

关于python-3.x - 错误: Format: "svg" not recognized.使用以下之一:,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62769161/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com