marcotcr / lime

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

TypeError: list indices must be integers or slices, not tuple". #642

Open tadepoju opened 3 years ago

tadepoju commented 3 years ago

I am also getting the same error as mentioned in issue #632

" labels_column = neighborhood_labels[:, label] TypeError: list indices must be integers or slices, not tuple".

This seems like an issue related to something happening within the lime_base script as I have no tuples in my code and any lists I index are solely with indices.

I hadn't realised it was specifically impacted by the number of samples. I also do not need 5000 samples so ideally would like to find a solution to make it work with a lower number of samples without getting that error.

stereolith commented 2 years ago

Hello @tadepoju , I happend upon this error as well. I turns out the predictor method that is passed to the explain_instance method needs to return a numpy array, because it access the values via multidimensional slicing.

Solution: Return a numpy array in the prediction function. You can transform a regular nested list as follows: prediction = np.array(prediction)

Hope this helps!