I have been trying to convert the final decision tree visualization dotfile to .png file using graphviz in python.

But It gives me an error below. I am not sure what I have been doing wrong.

Any help will be appreciated.




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)


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') 



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

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


Traceback (most recent call last):

File "", line 1, in runfile('/home/saul/pythonWork/DTRegressor_test.py', wdir='/home/saul/pythonWork')

File "/home/saul/anaconda3/lib/python3.7/site-packages/spyder_kernels/customize/spydercustomize.py", line 786, in runfile execfile(filename, namespace)

File "/home/saul/anaconda3/lib/python3.7/site-packages/spyder_kernels/customize/spydercustomize.py", line 110, in execfile exec(compile(f.read(), filename, 'exec'), namespace)

File "/home/saul/pythonWork/DTRegressor_test.py", line 82, in graph.render('dtree_render', view=True)

File "/home/saul/.local/lib/python3.7/site-packages/graphviz/files.py", line 188, in render rendered = backend.render(self._engine, format, filepath, renderer, formatter)

File "/home/saul/.local/lib/python3.7/site-packages/graphviz/backend.py", line 183, in render run(cmd, capture_output=True, check=True, quiet=quiet)

File "/home/saul/.local/lib/python3.7/site-packages/graphviz/backend.py", line 150, in run raise ExecutableNotFound(cmd)

ExecutableNotFound: failed to execute ['dot', '-Tpdf', '-O', 'dtree_render'], make sure the Graphviz executables are on your systems' PATH

0 Answers