marcotcr / lime

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

OverflowError: Python int too large to convert to C long #598

Open dulanafdo opened 3 years ago

dulanafdo commented 3 years ago

I'm using Lime explainer.explain_instance to identify the local behaviour of the Autogluon model which I was trained (for a regression problem)

This is the line of the code which gives me the error:

`def new_predictor(point):
  pd_point = pd.DataFrame(point, columns=feature_names)
  pred = np.array(predictor.predict(pd_point))
  return pred

exp = explainer.explain_instance(
        data_row= data.iloc[j], 
        predict_fn=new_predictor
    )`

This code worked. but when I'm trying to loop this and run this for several set of points, this works for some points and breaks with this error

This is the error which I'm getting:

Traceback (most recent call last):
  File "d:/Ongoing Projects/Feature importance-LIME Loop.py", line 96, in <module>
    exp = explainer.explain_instance(
  File "D:\Ongoing Projects\.venv\lib\site-packages\lime\lime_tabular.py", line 340, in explain_instance
    data, inverse = self.__data_inverse(data_row, num_samples)
  File "D:\Ongoing Projects\.venv\lib\site-packages\lime\lime_tabular.py", line 546, in __data_inverse
    inverse_column[0] = data[0, column]
OverflowError: Python int too large to convert to C long

Please help me to fix this issue.

pwharned commented 3 years ago
Screen Shot 2021-05-18 at 4 40 49 PM

Issue is that the number you are trying to pass is greater than sys.maxsize. this could be fixed by casting inverse_column as float, as you can see in the screenshot

marcotcr commented 3 years ago

Your prediction function should take a list or array as input, and output a 2d array of prediction probabilities.

marcotcr commented 3 years ago

maybe I misunderstood and @pwharned actually got it. I'll wait