Anchor your Model Interpretation by Anchors
Model interpretation means providing reason and the logic behind in order to enable the accountability and transparency on model. As mentioned in previous blog (Introduction to Model Interpretation and SHAP), model interpretation is important for data science to gain the trust from managements and customers.
LIME authors mentioned that LIME unable to explain the model correctly on some scenarios. Therefore, they proposed a new way to perform model interpretation which is Anchors.
After reading this article, you will understand:
- Limitation of LIME Explanation
- New Method: Anchors
Limitation of LIME Explanation

Although we can use simple function to interpret complexity locally, it can only explain the particular instance. It means that it may not able to fit for unseen instance.
From above LIME explanation on sentiment prediction, “not” provides a positive influence in left hand side while it is heavy negative influence in right hand side. It is fine if we look into either one explanation but we will be confused if we see both explanation together.
New Method: Anchors

By learning the line (or slope), LIME explains the prediction result. Different from LIME, Anchors uses “local region” to learn how to explain the model. The “local region” refer to a better construction of generated data set for explanation.
There are two approaches to find anchors. The first one is buttom-up approach which is simple but desired for more time to compute result. The second one is beam search which is adopted in “Anchors” library.
Bottom-up Approach

This method starts from empty set. In every iteration, it will generate a set of candidates and new feature predicate (feature input) will be added once a time. If the rule reach the precision and meets the criteria of equation 3, it will stop to find next feature predicate. As it targets to find the shortest anchor because they noted that short anchors are likely to have a higher coverage.
Intuitively, there are two major issues. Only one feature can be add a time. Also, the primary object of greedy search is identifying the shortest path.
Beam-Search Approach

This approaches address the limitation of greedy search. It uses KL-LUCB algorithm to select those best candidates. Expected result is that this approach more likely to identify an anchor with higher coverage than bottom-up search.
Implementation
explainer = anchor_text.AnchorText(spacy_nlp, labels, use_unk_distribution=True)
exp = explainer.explain_instance(x_test[idx], estimator, threshold=0.8, use_proba=True, batch_size=30)
max_pred = 2
print('Key Singal from Anchors: %s' % (' AND '.join(exp.names())))
print('Precision: %.2f' % exp.precision())
print()
exp.show_in_notebook()
When calling “explain_instance”, we need to provide
- x_test[idx]: The target of x
- estimator: Your model
- threshold: Anchors use this threshold to find the minimum precision to include a anchor (feature)
- batch_size: Number of batch you want to generate. More batch means generating more possible data set but it needs to take longer as well

From the above explanation, Anchors provides that “India” is the import anchor to classify the input as “b” category.
Takeaway
To access all code, you can visit my github repo.
- Comparing to SHAP, computation time is less.
- In my previous, I use both SHAP and Anchors to explain the prediction. You may also consider to use multiple model interpreter.
- Label can only accept integer. Means that you cannot pass exact classification name but the encoded category.
About Me
I am Data Scientist in Bay Area. Focusing on state-of-the-art in Data Science, Artificial Intelligence , especially in NLP and platform related. You can reach me from Medium Blog, LinkedIn or Github.
Reference
Ribeiro M. T., Singh S., and Guestrin C.. “Why Should I Trust You?” Explaining the Predictions of Any Classifier. 2016. https://arxiv.org/pdf/1602.04938.pdf
Ribeiro M. T., Singh S., and Guestrin C.. Anchors: High-Precision Model-Agnostic Explanations. 2018. https://homes.cs.washington.edu/~marcotcr/aaai18.pdf
Kaufmann E., Kalyanakrishnan S. “Information Complexity in Bandit Subset Selection” 2013. http://proceedings.mlr.press/v30/Kaufmann13.pdf