Iris DataSet, IndexError: list index out of range
achraf-azize opened this issue · comments
Hello,
I am trying to use Anchor to explain predictions on the Iris DataSet.
When I try to explain the index 50, it doesn't work.
But with 57 and more, it starts working, then not. It's weird !
This is the code I run:
'''
from sklearn import datasets
from xgboost import XGBClassifier
iris = datasets.load_iris()
X_clf = iris.data
y_clf = iris.target
XGB_clf = XGBClassifier()
XGB_clf.fit(X_clf, y_clf)
explainer = anchor_tabular.AnchorTabularExplainer(
['0','1','2'],
iris.feature_names,
X_clf,)
exp = explainer.explain_instance(X_clf[50], XGB_clf.predict, threshold=0.95)
'''
And I get the error:
IndexError Traceback (most recent call last)
in
---> 18 exp = explainer.explain_instance(X_clf[50], XGB_clf.predict, threshold=0.95)
c:\users\azizeac\venv\lib\site-packages\anchor\anchor_tabular.py in explain_instance(self, data_row, classifier_fn, threshold, delta, tau, batch_size, max_anchor_size, desired_label, beam_size, **kwargs)
280 desired_confidence=threshold, max_anchor_size=max_anchor_size,
281 **kwargs)
--> 282 self.add_names_to_exp(data_row, exp, mapping)
283 exp['instance'] = data_row
284 exp['prediction'] = classifier_fn(self.encoder_fn(data_row.reshape(1, -1)))[0]
c:\users\azizeac\venv\lib\site-packages\anchor\anchor_tabular.py in add_names_to_exp(self, data_row, hoeffding_exp, mapping)
310 if f in self.categorical_names:
311 v = int(v)
--> 312 if ('<' in self.categorical_names[f][v]
313 or '>' in self.categorical_names[f][v]):
314 fname = ''
IndexError: list index out of range
Wow, this was a weird bug, only happens if you instantiate the explainer more than once (which I'm guessing you did).
Fixed in e02c950