I am going through https://towardsdatascience.com/explain-your-model-with-the-shap-values-bc36aac4de3d trying to get the force_plot to print.
I'm running Python 3.8.5 on Ubuntu 20.04
I run this code:
shap.initjs()
# Write in a function
random_picks = np.arange(1,330,50) # Every 50 rows
S = X_test.iloc[random_picks]
def shap_plot(j):
explainerModel = shap.TreeExplainer(xg_clf)
shap_values_Model = explainerModel.shap_values(S)
p = shap.force_plot(explainerModel.expected_value, shap_values_Model[j], S.iloc[[j]])
return(p)
z = shap_plot(3)
and I get <shap.plots._force.AdditiveForceVisualizer object at 0x7f1568cac070>
to return.
I'm not a python expert, so I've tried looking at this data:
display(z)
whieh isn't defined.
and print(z) which just returns the name of the object, and doesn't help me to see what was plotted.
I've also tried using matplotlib which is already loaded,
def shap_plot(j):
explainerModel = shap.TreeExplainer(xg_clf)
shap_values_Model = explainerModel.shap_values(S)
p = shap.force_plot(explainerModel.expected_value, shap_values_Model[j], S.iloc[[j]])
plt.savefig('tmp.svg')
plt.close()
return(p)
shap_plot(3)
but this just gives an empty image.
If there is an error, I don't see it.
How can I get this shap.force_plot to show the image?