shap icon indicating copy to clipboard operation
shap copied to clipboard

Plot_waterfall() error

Open Pablomoreiragarcia opened this issue 2 years ago • 2 comments

I'm trying to plot a waterfall diagram with this explainer:

ex = shap.Explanation(shap_values[0], 
                      explainer.expected_value,
                      X.iloc[0],  
                      columns)

shap.waterfall_plot(ex)

but I'm getting this error:

---------------------------------------------------------------------------
IndexError                                Traceback (most recent call last)
/tmp/ipykernel_22791/3628025354.py in <module>
----> 1 shap.waterfall_plot(ex)

/usr/local/lib/python3.8/dist-packages/shap/plots/_waterfall.py in waterfall(shap_values, max_display, show)
    120             yticklabels[rng[i]] = feature_names[order[i]]
    121         else:
--> 122             yticklabels[rng[i]] = format_value(features[order[i]], "%0.03f") + " = " + feature_names[order[i]]
    123 
    124     # add a last grouped feature to represent the impact of all the features we didn't show

/usr/local/lib/python3.8/dist-packages/shap/utils/_general.py in format_value(s, format_str)
    232         s = format_str % s
    233     s = re.sub(r'\.?0+$', '', s)
--> 234     if s[0] == "-":
    235         s = u"\u2212" + s[1:]
    236     return s

IndexError: string index out of range

If I print ex, I receive it:

.values =
array([-2.27243590e-01,  5.41666667e-02,  3.33333333e-03,  2.21153846e-02,
        1.92307692e-04, -7.17948718e-02])

.base_values =
0.21923076923076923

.data =
BMI                                          18.716444
ROM-PADF-KE_D                                       33
Asym-ROM-PHIR(≥8)_discr                              1
Asym_SLCMJLanding-pVGRF(10percent)_discr             1
Asym_TJ_Valgus_FPPA(10percent)_discr                 1
DVJ_Valgus_KneeMedialDisplacement_D_discr            0
Name: 0, dtype: object

And I don't know how to solve it.

Pablomoreiragarcia avatar Jun 06 '22 17:06 Pablomoreiragarcia