zdz
zdz

Reputation: 347

KeyError: 1 in using SP_LIME with Lightgbm

I am using SP_LIME explanation for results for churn prediction based on Lightgbm model. Using LIME explainer.explain_instance works OK.

When I try SP_LIME on the same dataset first part sp_obj = submodular_pick.SubmodularPick(explainer, data_source[model_lgbm.feature_name()].values, prob, num_features=5,num_exps_desired=10) also works OK. I become the following results:

Intercept -0.017232899377758105
Prediction_local [0.50051062]
Right: 0.9748700776391315
Intercept -0.016903088945780256
Prediction_local [0.28478504]
Right: 0.5419652445350156

and I got the following error after code for ploting :

[exp.as_pyplot_figure(label=1) for exp in sp_obj.sp_explanations]

KeyError                                  Traceback (most recent call last)
<ipython-input-140-cf85e71256d4> in <module>
----> 1 [exp.as_pyplot_figure(label=1) for exp in sp_obj.sp_explanations]

<ipython-input-140-cf85e71256d4> in <listcomp>(.0)
----> 1 [exp.as_pyplot_figure(label=1) for exp in sp_obj.sp_explanations]

~\AppData\Local\Continuum\anaconda3\envs\use-case\lib\site-packages\lime\explanation.py in as_pyplot_figure(self, label, **kwargs)
    167         """
    168         import matplotlib.pyplot as plt
--> 169         exp = self.as_list(label=label, **kwargs)
    170         fig = plt.figure()
    171         vals = [x[1] for x in exp]

~\AppData\Local\Continuum\anaconda3\envs\use-case\lib\site-packages\lime\explanation.py in as_list(self, label, **kwargs)
    141         """
    142         label_to_use = label if self.mode == "classification" else self.dummy_label
--> 143         ans = self.domain_mapper.map_exp_ids(self.local_exp[label_to_use], **kwargs)
    144         ans = [(x[0], float(x[1])) for x in ans]
    145         return ans

KeyError: 1 ```

Any idea what is going on here?

Upvotes: 2

Views: 1121

Answers (1)

help
help

Reputation: 11

Change the label 1 to 0. [exp.as_pyplot_figure(label=0) for exp in sp_obj.sp_explanations]

Upvotes: 1

Related Questions