Skip to content
Advertisement

Why are shap values changing every time I call shap.plots.beeswarm?

So here’s my code using shap :

enter image description here

Since I just plot three times the same shape values, I’d expect the three plots to be the same. However, it keeps on changing. After some research, it seems that a new value appear at the top at each call, but why ? Is it a bug in shap ?

Edit 1 : I tried loading the same model between each call of shap.plots.beeswarm, but the results are still different.

Advertisement

Answer

Thanks to @jared_mamrot I could find a solution. I just had to change the code of shap’s function beeswarm :

JavaScript

replaced by :

JavaScript

Make sure to import the library at the top of the code :

JavaScript

Edit : If you don’t want to change the source code, just give a deep copy of shap_values while calling beeswarm like so :

JavaScript
Advertisement