AIX360 icon indicating copy to clipboard operation
AIX360 copied to clipboard

LIME explain_instance documentation discrepancy

Open Vildemort opened this issue 5 years ago • 1 comments

lime-ml.readthedocs says that explain_instance for tabular lime expects a 1D-array as input, but when running the code with 1D-array the following error message occurs: ValueError: Expected 2D array, got 1D array instead: [1, 2, 3, 4, 5]

Does the function expect 2D or 1D- arrays?

Edit: Should probably mention that I get the same error message when passing 2D arrays (for example [[1,2,3,4,5]]). The problem probably lies elsewhere, but the error message is not very helpful.

Vildemort avatar Nov 12 '19 14:11 Vildemort

@Vildemort You can look at the following notebook for an example of using the lime tabular explainer: https://github.com/marcotcr/lime/blob/master/doc/notebooks/Tutorial%20-%20continuous%20and%20categorical%20features.ipynb

In the above example, explain_instance is called as: exp = explainer.explain_instance(test[i], rf.predict_proba, num_features=2, top_labels=1)

Here: test[i].shape is (4,) so its 1D array. rf.predict_proba (or a custom predict function that we define and pass here) accepts a batch of inputs so it would accepts 2d-arrays for iris example as each data instance is a 1D array. Hope this helps.

vijay-arya avatar Nov 18 '19 15:11 vijay-arya