A Dive Into Explainable AI

What is Explainability?

Explainability in AI is how much your features contribute or how important is your feature for the given output. Explainable AI (XAI) can be considered the collection of processes that help the developer, and the users understand and interpret the results.

  • How do users trust the AI model in an autonomous vehicle to make the right decisions in a high traffic scenario?
  • How to make the doctor trust the inference of the AI model diagnosing a particular disease?

The image provides a visual representation of XAI and how it potentially affects the end-user.

For Example,

If we have a linear model, feature importance is calculated by the magnitude of weights. If we have tree-based models, feature importance is calculated by Information gain or entropy. For deep learning models, we calculate using Integrated gradients.

Why does a Machine Learning Model need to be interpretable?

In this article, I will walk you through one technique that makes any machine learning model interpretable. Generally, there is a misconception that only linear machine learning models are more interpretable than others. The Model Explainability helps in decision making and gives clients reliability.

Many of these AI systems are black-box, meaning we don’t understand how they work and why they make such decisions.

Can we have a model agnostic explainability?

A Research Paper named “Why Should I Trust You?” published by Marco Tulio Ribeiro, Sameer Singh, and Carlos Guestrin from the University of Washington in 2016 explains two techniques.

The two techniques are:

  • LIME (Local Interpretable Model-agnostic Explanations)
  • SHAP (SHapley Additive exPlanations)

In this blog, we will cover the in-depth intuition of the LIME technique.

Local Interpretable Model-agnostic Explanations (LIME)

LIME aims to identify an interpretable model over the interpretable representation that is locally faithful to the classifier.

Local Interpretability answers the question, “Why is the model behaving in a specific way in the locality of a data point x?”. LIME only looks at the local structure and not the global structure of the data.

The high-level intuition is to consider the dark red + named X from the above diagram and take the data points neighbouring X. From the above image, we can see those points closer to X have higher weightage and the points which are farther have lower weightage. Sample a bunch of points near X and fit a surrogate model g() (consider g () as Linear Model). The surrogate model approximates the f() model in the neighbourhood of X. f() is the final black-box model, were given an input x, we’ll get the output y.

Advantageds of LIME

  • Works well on Images, Text, and Tabular data.
  • Model Agnostic.
  • K Lasso give s highly interpretable K features.

Disadvantages of LIME

  • Determining the right neighborhood Πx(z).
  • Determining the correct kernel Width σ.
  • The distance metric D(x, z) does not work well for high-dimensional data.

Code for Installing LIME

Install LIME using:

pip install lime

Let’s take Wine quality dataset, for example.

The data is split into train and test

from sklearn.model_selection import train_test_split
X = wine.drop(‘quality’, axis=1)
y = wine[‘quality’]
X_train, X_test, y_train, y_test = train_test_split(
X, y, test_size=0.2, random_state=42)

For this example, we are using Random Forest Classifier.

from sklearn.ensemble import RandomForestClassifier
model = RandomForestClassifier(random_state=42)
model.fit(X_train, y_train)
score = model.score(X_test, y_test)

The Lime Library has a module named lime_tabular, which creates a tabular Explainer object. The parameters are:

  • training_data – Training data must be in a NumPy array format.
  • feature_names – Column names from the training set
  • class_names – Distinct classes from the target variable
  • mode – Classification in our Case

import lime
from lime import lime_tabular
explainer = lime_tabular.LimeTabularExplainer(
training_data=np.array(X_train),
feature_names=X_train.columns,
class_names=[‘bad’, ‘good’],
mode=’classification’)

The LIME library has an explain_instance function of the explainer object. The parameters required are:

  • data_row – a single data point from the dataset
  • predict_fn – a function used to make predictions

exp = explainer.explain_instance(
data_row=X_test.iloc[1],
predict_fn=model.predict_proba)
exp.show_in_notebook(show_table=True)

The show_in_notebook is used for data visualization

The above diagrams show that the random forest classifier is 81% confident that the data point belongs to the “bad” class. The values of alcohol, sulfates, and total sulfur dioxide elevate the chances of the data point being “bad.” There are different visualization techniques available in the LIME library.

Conclusion
  • The applications of Explainable AI(XAI) frameworks will continue to grow, enabling us to develop more robust and complex solutions in a ‘White-Box’ approach.
  • XAI will enable both data scientists and stakeholders to understand complex data predictions. The LIME library also provides great visualization. By building such an interpretable model,s you gain acceptance and trust from the stakeholders.
  • Besides LIME, examples of other explainable AI tools like IBM AIX 360, What-if Tool, and Shap can help increase the interpretability of the data and machine learning models.

About the Author

Leave a Reply

Your email address will not be published. Required fields are marked *

You may also like these