0

How to save the shap partial dependance plot as a pdf?

What have I tried?

shap.partial_dependence_plot(
    "B", model.predict, X100, ice=False, show=False,
    model_expected_value=True, feature_expected_value=True
)

plt.show()
plt.draw()
plt.savefig('K.pdf',bbox_inches='tight', dpi=600)
#fig = plt.figure()
  • So, you've tried that, and what was the result? An error? Two PDF's? No PDF? Remember, we can't see your screen. – Saaru Lindestøkke Feb 06 '23 at 21:16
  • @SaaruLindestøkke. Thanks. The result was a blank pdf. Would you please advise? – user20155022 Feb 06 '23 at 21:17
  • Where do you set the value of `plt`? In your example code it seems to be set nowhere. – Saaru Lindestøkke Feb 06 '23 at 21:24
  • Does this answer your question? [How to save a plot (generated by shap\_values) to png?](https://stackoverflow.com/questions/57976902/how-to-save-a-plot-generated-by-shap-values-to-png) – Saaru Lindestøkke Feb 06 '23 at 21:38
  • Thanks. I am still getting an empty pdf. – user20155022 Feb 06 '23 at 21:47
  • Can you [edit] your question to show what you've tried from the suggested question? Did you set `show=False`? – Saaru Lindestøkke Feb 06 '23 at 21:49
  • You need to capture the output (which is a [figure with axes](https://github.com/slundberg/shap/blob/master/shap/plots/_partial_dependence.py#L199)) when you do the shap plot. Once you have that you should be able to show that figure and save that figure. You are currently not capturing anything, just runnig the `shap` command. – Saaru Lindestøkke Feb 06 '23 at 21:53
  • The figure is displayed. The problem is I cannot save it. I just need it with a good resolution to finish my work. – user20155022 Feb 06 '23 at 21:58
  • Have you seen this: https://stackoverflow.com/q/52137579/1256347 Please, pretty please, show some research in your question, show what you've tried so far and show what errors you get in every try, such that I (and others) don't have to suggest things you've tried and didn't work. – Saaru Lindestøkke Feb 06 '23 at 22:09
  • Thanks so much. Yes, I've seen this, it did not work for me. I apologize for bothering you. I have an alternative approach for this but I don't know if you can help.. Would you please be kind enough to check this query? https://stackoverflow.com/questions/75349991/how-to-modify-a-partial-dependance-plot?noredirect=1#comment132963458_75349991 – user20155022 Feb 06 '23 at 22:15
  • Sorry, you're making the same mistake with that question: you don't [show any research](https://stackoverflow.com/help/how-to-ask), which makes it hard to help you. Good luck! – Saaru Lindestøkke Feb 06 '23 at 22:20

0 Answers0