marcotcr / lime

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

Apply LIME for CNN + Regression gives error #585

Closed OnkarMulay closed 3 years ago

OnkarMulay commented 3 years ago

Code %%time %load_ext autoreload %autoreload 2 import os,sys from skimage.segmentation import mark_boundaries from lime import lime_image import lime

explainer = lime_image.LimeImageExplainer() explanation = explainer.explain_instance(images[0].astype('double'), model.predict, top_labels=1, hide_color=0, num_samples=1)


Error IndexError Traceback (most recent call last)

in ~\anaconda3\lib\site-packages\lime\lime_image.py in explain_instance(self, image, classifier_fn, labels, hide_color, top_labels, num_features, num_samples, batch_size, segmentation_fn, distance_metric, model_regressor, random_seed) 214 (ret_exp.intercept[label], 215 ret_exp.local_exp[label], --> 216 ret_exp.score, ret_exp.local_pred) = self.base.explain_instance_with_data( 217 data, labels, distances, label, num_features, 218 model_regressor=model_regressor, ~\anaconda3\lib\site-packages\lime\lime_base.py in explain_instance_with_data(self, neighborhood_data, neighborhood_labels, distances, label, num_features, feature_selection, model_regressor) 180 181 weights = self.kernel_fn(distances) --> 182 labels_column = neighborhood_labels[:, label] 183 used_features = self.feature_selection(neighborhood_data, 184 labels_column, IndexError: too many indices for array: array is 1-dimensional, but 2 were indexed
marcotcr commented 3 years ago

It sounds like model.predict just outputs a single label, rather than an array of prediction probabilities.