尝试将DecisionTreeRegression的决策树可视化的点文件转换为.png文件时出错

时间:2019-05-05 11:58:34

标签: python-3.x graphviz decision-tree

我一直在尝试使用python中的graphviz将最终决策树可视化点文件转换为.png文件。

但是下面给了我一个错误。我不确定自己在做什么错。

任何帮助将不胜感激。

谢谢

扫罗

代码:

import numpy as np

import matplotlib.pyplot as plt 

from sklearn.tree import DecisionTreeRegressor  

from sklearn.tree import export_graphviz

from subprocess import call

from IPython.display import Image

import pydotplus

from subprocess import check_call

import graphviz

dataset = np.array( 
[['Asset Flip', 100, 1000], 
['Text Based', 500, 3000], 
['Visual Novel', 1500, 5000], 
['2D Pixel Art', 3500, 8000], 
['2D Vector Art', 5000, 6500], 
['Strategy', 6000, 7000], 
['First Person Shooter', 8000, 15000], 
['Simulator', 9500, 20000], 
['Racing', 12000, 21000], 
['RPG', 14000, 25000], 
['Sandbox', 15500, 27000], 
['Open-World', 16500, 30000], 
['MMOFPS', 25000, 52000], 
['MMORPG', 30000, 80000] 
]) 


X= dataset[:,1:2].astype(int) #covert to integer

y = dataset[:, 2].astype(int)  

reg = DecisionTreeRegressor(random_state=0)

reg.fit(X,y)

pred_case = reg.predict([[3750]])

print("Predicted price: % d\n"% pred_case)  

X_grid = np.arange(min(X), max(X), 0.01)
X_grid = X_grid.reshape((len(X_grid), 1))
plt.scatter(X, y, color='red')

plt.plot(X_grid, reg.predict(X_grid), color = 'blue')  

plt.title('Profit to Production Cost (Decision Tree Regression)')  

plt.xlabel('Production Cost') 

plt.ylabel('Profit') 

plt.show() 

dotfile = export_graphviz (reg, out_file = None, feature_names =        ['Production Cost'])

graph = graphviz.Source(dotfile)
graph.render('dtree_render', view=True)

错误:

回溯(最近通话最近一次):

文件“”,第1行,在     runfile('/ home / saul / pythonWork / DTRegressor_test.py',wdir ='/ home / saul / pythonWork')

runfile中的文件“ /home/saul/anaconda3/lib/python3.7/site-packages/spyder_kernels/customize/spydercustomize.py”,第786行     execfile(文件名,命名空间)

exec文件中的文件“ /home/saul/anaconda3/lib/python3.7/site-packages/spyder_kernels/customize/spydercustomize.py”,第110行     exec(compile(f.read(),文件名,'exec'),命名空间)

文件“ /home/saul/pythonWork/DTRegressor_test.py”,第82行,在     graph.render('dtree_render',view = True)

文件“ /home/saul/.local/lib/python3.7/site-packages/graphviz/files.py”,第188行,在渲染中     渲染= backend.render(self._engine,格式,文件路径,渲染器,格式化程序)

文件“ /home/saul/.local/lib/python3.7/site-packages/graphviz/backend.py”,第183行,在渲染中     运行(cmd,capture_output = True,check = True,quiet = quiet)

文件“ /home/saul/.local/lib/python3.7/site-packages/graphviz/backend.py”,第150行,正在运行     提高ExecutableNotFound(cmd)

ExecutableNotFound:无法执行['dot','-Tpdf','-O','dtree_render'],请确保Graphviz可执行文件位于系统的PATH中

0 个答案:

没有答案