【发布时间】:2020-09-22 16:43:56
【问题描述】:
我尝试使用 XGBoost 绘制决策树
Plot a Single XGBoost Decision Tree。和https://machinelearningmastery.com/visualize-gradient-boosting-decision-trees-xgboost-python/。
我的代码:
import matplotlib.pyplot as plt
import xgboost as xgb
model = xgb.XGBClassifier()
model.load_model("./models/acute_inflammations.model")
#res = model.predict_proba(X_test.iloc[0:1])
xgb.plot_tree(model)
plt.show()
模型是使用save_model 方法保存的,并且正在以其他方式工作(我已经尝试使用它进行预测)。唯一的问题是 plot_tree 函数,它返回以下错误:
Format: "png" not recognized. Use one of:
Traceback (most recent call last):
File "C:/Users/jakub/Desktop/thesis_ML/main.py", line 35, in <module>
xgb.plot_tree(model)
File "C:\Users\jakub\anaconda3\envs\Inz_ML\lib\site-packages\xgboost\plotting.py", line 248, in plot_tree
s.write(g.pipe(format='png'))
File "C:\Users\jakub\anaconda3\envs\Inz_ML\lib\site-packages\graphviz\files.py", line 136, in pipe
out = backend.pipe(self._engine, format, data,
File "C:\Users\jakub\anaconda3\envs\Inz_ML\lib\site-packages\graphviz\backend.py", line 244, in pipe
out, _ = run(cmd, input=data, capture_output=True, check=True, quiet=quiet)
File "C:\Users\jakub\anaconda3\envs\Inz_ML\lib\site-packages\graphviz\backend.py", line 183, in run
raise CalledProcessError(proc.returncode, cmd,
graphviz.backend.CalledProcessError: Command '['dot', '-Tpng']' returned non-zero exit status 1. [stderr: b'Format: "png" not recognized. Use one of:\r\n']
Process finished with exit code 1
我在 Windows(下载页面中的“Stable 2.44 Windows 安装包”)和 Python (pip install graphviz) 中都安装了 Graphviz。 Graphviz 在我的 PATH 系统变量中。我究竟做错了什么?我怎样才能解决这个问题?我什至可以解决这个问题,还是 XGBoost 内部的某些东西随着最近的 Graphviz 更新而改变(他们最近更新了)?
【问题讨论】:
-
不能使用2.4.4的版本