marcotcr / lime

Lime: Explaining the predictions of any machine learning classifier
BSD 2-Clause "Simplified" License
11.59k stars 1.81k forks source link

In multiclass explanations local_pred and score are only stored for last label #506

Closed expectopatronum closed 3 years ago

expectopatronum commented 4 years ago

Hi, when using lime for multi class explanations I noticed that local_pred and score are only stored for the last label. This is because they are overwritten in the loop:

        for label in top:
            (ret_exp.intercept[label],
             ret_exp.local_exp[label],
             ret_exp.score, ret_exp.local_pred) = self.base.explain_instance_with_data(
                data, labels, distances, label, num_features,
                model_regressor=model_regressor,
                feature_selection=self.feature_selection)

To make sure I printed the output in the notebook "Tutorial - images - Pytorch": image

If you agree this shouldn't be the case I can fix this by implementing local_pred and score as dictionaries like intercept and local_exp.

Best regards Verena

marcotcr commented 4 years ago

Yes, that is a bug. I guess making it a dict is the right thing to do, but it will be a breaking change if people are already using it. But yeah, whatever, if you do a pull request I'll accept. Thanks!