Hello!
I have creeated a pipeline in Model Studio (DM and ML) with a Python Open Surce node where i have built a decision tree model. The node works fine and in the Reuslts window i can extract various things e.g. the variable improtance of the tree. What i am also trying to do is to output a plot of the tree. I use the following python script:
tree.plot_tree(dm_model,filled=True,rounded=True,class_names=["Reject","Grant"],feature_names=X_enc.columns, fontsize=6) plt.show()
The node works fine (green sign after the pipeline is ran) but there is not plot in the results. Do i need to add something more in the python script to have the desired result (decsiion tree viusual-plot).
Thanks in advance,
Andreas
Hi Andreas,
For the plot to show up in the node results, you need to: (1) save it in jpg, png or gif format, (2) name it with rpt_ prefix, for example rpt_treeplot.png or rpt_treeplot.jpg and (3) save it in dm_nodedir folder (dm_nodedir is a variable available in the node editor pointing to a temporary working folder)
Here is some sample Python code that does this:
# Plot model residuals
plt.scatter(pred, pred - dm_inputdf[dm_dec_target])
plt.axhline(y=0, color='r')
plt.title('Residual plot')
plt.ylabel('Residual')
plt.savefig(dm_nodedir + '/rpt_residuals.png')
plt.close()
Hope this helps,
Radhikha
Hi Andreas,
For the plot to show up in the node results, you need to: (1) save it in jpg, png or gif format, (2) name it with rpt_ prefix, for example rpt_treeplot.png or rpt_treeplot.jpg and (3) save it in dm_nodedir folder (dm_nodedir is a variable available in the node editor pointing to a temporary working folder)
Here is some sample Python code that does this:
# Plot model residuals
plt.scatter(pred, pred - dm_inputdf[dm_dec_target])
plt.axhline(y=0, color='r')
plt.title('Residual plot')
plt.ylabel('Residual')
plt.savefig(dm_nodedir + '/rpt_residuals.png')
plt.close()
Hope this helps,
Radhikha
Available on demand!
Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.
Use this tutorial as a handy guide to weigh the pros and cons of these commonly used machine learning algorithms.
Find more tutorials on the SAS Users YouTube channel.