Blog

Sep 1, 2017 · post

Why your relationship is likely to last (or not): using Local Interpretable Model-Agnostic Explanations (LIME)

Henry VIII of England had many relationships. We build a classifier to predict whether relationships are going to last, or not, and used Local Interpretable Model-Agnostic Explanations (LIME) to understand the predicted success or failure of given relationships.

Last month we launched the latest report and prototype from our machine intelligence R&D team, Interpretability, and we shared our view on why interpretability matters for business.

On September 6, we will host a public webinar on interpretability where we’ll be joined by guests Patrick Hall (Senior Director for Data Science Products at H2o.ai, co-author of Ideas on Interpreting Machine Learning) and Sameer Singh (Assistant Professor of Computer Science at UC Irvine, co-creator of LIME). There will be lots of opportunities for the audience to ask questions, so we hope you’ll join us!

During our research, we built an interpretability prototype called Refractor to better understand the reasons why a subscription business loses customers. This prototype depends on Local Interpretable Model-Agnostic Explanations (LIME), a new algorithm and open source tool for interpreting the behavior of machine learning models that was released last year (paper, code).

We discuss LIME in depth in our report, but in this article, we take look at it from a conceptual perspective and apply LIME to a binary classification problem: predicting whether couples stay together, or not.

Why we need interpretability, especially now

Algorithms decide which emails reach our inboxes, whether we are approved for credit, and whom we get the opportunity to date. But, as algorithms give answers, they raise questions. If an algorithm denies your loan application, wouldn’t you like to know why or what you could change for a more positive outcome? Or perhaps you’d like to know if your bank is right to trust the algorithm in the first place.

Fundamentally, machine learning algorithms learn relationships between inputs and outputs. During model training, we supply examples of these inputs and outputs as “learning material” and the algorithm learns the relationship, a parametrized function or trained model. It uses this model to provide outputs for novel inputs.

Some relationships are simple and can be captured by simple, linear models, which are easy to inspect and understand. For example, the probability of loan default increases with loan amount and decreases with income. These models are interpretable, meaning, they allow a qualitative understanding between inputs and outputs.

loan default

The simple, linear relationship between income, loan amount, and loan default.

But some relationships are complex. A customer’s decisions to cancel a subscription, the focus of our Refractor prototype, or the long-term success of a romantic relationship may depend on multiple factors in non-linear ways. To accurately model these relationships we need models with the flexibility to capture that complexity. Models such as random forests, gradient boosted trees, and neural networks can do just that. But, these complex models are intrinsically difficult to inspect, understand and interpret.

complex decision surface

Complex, non-linear relationships, as shown in this figure, cannot be captured by simple models. Models that can capture this complexity tend to be less interpretable.

The promise of interpretability for practitioners

Interpretability means we can understand the reasons why an algorithm gave a particular response. In a recent blog post we cover why, from a business perspective, one should care about interpretability.

But data scientists and machine learning practitioners benefit from interpretability, too. Interpretability ensures that a model is right for the right reasons and wrong for the right reasons, which traditional measures of model performance, such as model accuracy on the hold-out test set, cannot capture. Insights into the model can help improve it and can help build trust that the model, once deployed, will continue to do a good job.

One approach to ensure interpretability is to use simple models, but the trade-off between interpretability and accuracy means that, if relationships between inputs and outputs are complex, accuracy will suffer.

accuracy vs. interpretability

More accurate models tend to be harder to inspect and understand.

Another option is to use “white-box” models. These have been developed specifically to provide insight into their internal workings without sacrificing model accuracy too much. We cover white-box models in our report.

Model-agnostic interpretability and LIME

But what if you don’t want to (or can’t) change your model? Perhaps there’s no other way to get the accuracy you need. Perhaps it’s already in production. Or perhaps you didn’t make it and have no idea how it works. In these situation, “model-agnostic” interpretability tools such as LIME may be the right approach (paper, code). LIME is based on two simple ideas: perturbation and locally linear approximation.

Perturbation

Perturbation is probably exactly what you would do if you were asked to explore a black-box model. By repeatedly perturbing the input and observing its effect on the output you can develop an understanding of how different inputs relate to the original output.

LIME formalizes this idea. It takes a prediction you want to explain and systematically perturbs its inputs. These perturbed inputs become new, labelled training data for a simpler approximate model.

Locally linear approximation

LIME fits a linear model to describe the relationships between the (perturbed) inputs and outputs. In doing so, it weights generated labels close to the example more heavily to nudge the algorithm to focus on the most relevant part of the “decision function”. So, the simple linear algorithm approximates the more complex, non-linear function learned by the high-accuracy model locally, in the vicinity of the to-be-explained prediction.

locally linear approximation

Even complex decision functions can be approximated locally by simple linear models.

Based on two simple ideas, LIME is an exciting breakthrough. It allows you to train a model in any way you like and still have an answer to the local question, “Why has this particular decision been made?”

Putting LIME to work, explaining the (predicted) fate of romantic relationships

Love endures forever but when it doesn’t, wouldn’t you like to know why? We took the Stanford HCMST data (How Couples Meet and Stay Together), a longitudinal study on how American’s meet their partners, and build a classifier to predict whether (and why) couples are likely to stay together.

We modeled the relationship between couples and their relationship fate using a random forest classifier, a widely used ensemble model that is difficult to inspect and understand. Popular machine learning libraries offer simple ways to implement machine learning routines. We used sklearn's’ RandomForestClassifier for model training, GridSearchCV for hyperparameter tuning, and Pipeline to streamline data preprocessing. If you want to see the code, and experiment with LIME, you can access the notebook here.

To explain predictions, once we had a trained model, we needed to instantiate the LimeTabularExplainer object. It takes as inputs a list of feature names (feature_names) and class names (class_names), a list of all categorical variables (categorical_features) and a dictionary of the values of all categorical variables (categorical_names) in addition to the training data; LIME perturbs inputs according to the training data distribution.

from lime.lime_tabular import LimeTabularExplainer

# The Lime LimeTabularExplainer object
explainer = LimeTabularExplainer(
    train, # training data
    class_names=['BrokeUp', 'StayedTogether'], # class names
    feature_names=list(data.columns), # names of all features (regardless of type)
    categorical_features=categorical_features, # names of only categorical features
    categorical_names=categorical_names, # labels of all values of all categorical features 
    discretize_continuous=True
    )

The LimeTabularExplainer object has a method explain_instance that takes an example input and returns the top reasons for its corresponding prediction. The explain_instance method requires a function (pipeline.predict_proba) as input that takes the “raw” example input data, transforms, scales, one-hot encodes, etc. (as appropriate), and returns its prediction using the trained model. To see how we made ours, see our notebook.

example = 3
exp = explainer.explain_instance(test[example], pipeline.predict_proba, num_features=5)
print('Couples probability of staying together:', exp.predict_proba[1])
exp.as_pyplot_figure()

sklearn's Pipeline streamlines data preprocessing and helps build the function for the lime explain_instance method (see code). Why the trouble, you may wonder? We could supply scaled, one-hot encoded example input to the explain_instance method?

To explain predictions, we need to be able to understand the reasons returned by solutions like LIME. If LIME returned a sequence of numbers that, mathematically speaking, is a good explanation for a prediction, we would be none the wiser. Explanations needs to be given in a language and at the scale the we can understand; that’s why we need to bother with Pipeline.

Why relationships (are predicted to) fail

According to the model, across couples based on random forest’s feature importances only, your age, your partner’s age, and the difference in age between partners determines whether couples are going to stay together, or not. LIME shows that the reasons for likely relationship success vary from one couple to the next.

This couple is likely to stay together, the model gives it a 0.89 probability. LIME informs us that the prediction is due to the fact that the couple is married while their (young) age lowers their chances of relationship “success”.

This couple is likely to stay together, the model gives it a 0.75 probability. LIME informs us the prediction is due to the fact that the couple owns their home, they are matched in terms of the level of education, and the respondent is between 43 and 55 years. Curiously, living in an urban area and voting democrat is associated with a lower chance to staying together.

LIME captures nuances above feature importances, the variables the trained model deems important globally, across the entire data encountered during training (age, partner’s age, age difference). LIME focuses on individuals, not global patterns.

What LIME reasons are not (good for)

How about using algorithms to manage your love life strategically? The model suggests to look for a partner close in age. Should you ask for a pay increase, buy a house, or get married? We asked LIME.

Your chances of staying together aren’t bad, the model gives is a 0.79. But merely “living together” is hurting your chances, according to LIME.

Evaluating different options, getting married leads to the biggest increase in your chance of staying together. But, we advice against marrying tonight’s Tinder date. It may be tempting to treat LIME’s reasons as causes of the real-world phenomena the model is predicting; surely, a high amount of debt on my loan application is the reason (read “cause”) for my denied loan application (especially if a smaller debt amount would have changed the outcome).

Getting married increases your chance of staying together to 0.91. But, reasons are not causes. We advice against marrying tonight’s Tinder date.

Algorithmic relationship advice should be taken with a grain of salt, LIME reasons are not causes. Interpretability helps us understand the inner workings of models to improve these models, to help build trust in models, and to form hypotheses about phenomena in the real-world captured by models (that warrant rigorous tests).

What’s more, LIME picks up on patterns in the data learned by the model, it does not inform about reality. Data reflects current and past conventions and social practices (which we see in our results). LIME is no oracle, but it allows humans to enter a more collaborative relationship with black-box machine learning models, and question them when necessary.

As we’ve said before: “The future is algorithmic. White-box models and techniques for making black-box models interpretable offer a safer, more productive, and ultimately more collaborative relationship between humans and intelligent machines. We are just at the beginning of the conversation about interpretability and will see the impact over the coming years.”

Read more

Newer
Sep 7, 2017 · post
Older
Sep 1, 2017 · post

Latest posts

Nov 15, 2022 · newsletter

CFFL November Newsletter

November 2022 Perhaps November conjures thoughts of holiday feasts and festivities, but for us, it’s the perfect time to chew the fat about machine learning! Make room on your plate for a peek behind the scenes into our current research on harnessing synthetic image generation to improve classification tasks. And, as usual, we reflect on our favorite reads of the month. New Research! In the first half of this year, we focused on natural language processing with our Text Style Transfer blog series.
...read more
Nov 14, 2022 · post

Implementing CycleGAN

by Michael Gallaspy · Introduction This post documents the first part of a research effort to quantify the impact of synthetic data augmentation in training a deep learning model for detecting manufacturing defects on steel surfaces. We chose to generate synthetic data using CycleGAN,1 an architecture involving several networks that jointly learn a mapping between two image domains from unpaired examples (I’ll elaborate below). Research from recent years has demonstrated improvement on tasks like defect detection2 and image segmentation3 by augmenting real image data sets with synthetic data, since deep learning algorithms require massive amounts of data, and data collection can easily become a bottleneck.
...read more
Oct 20, 2022 · newsletter

CFFL October Newsletter

October 2022 We’ve got another action-packed newsletter for October! Highlights this month include the re-release of a classic CFFL research report, an example-heavy tutorial on Dask for distributed ML, and our picks for the best reads of the month. Open Data Science Conference Cloudera Fast Forward Labs will be at ODSC West near San Fransisco on November 1st-3rd, 2022! If you’ll be in the Bay Area, don’t miss Andrew and Melanie who will be presenting our recent research on Neutralizing Subjectivity Bias with HuggingFace Transformers.
...read more
Sep 21, 2022 · newsletter

CFFL September Newsletter

September 2022 Welcome to the September edition of the Cloudera Fast Forward Labs newsletter. This month we’re talking about ethics and we have all kinds of goodies to share including the final installment of our Text Style Transfer series and a couple of offerings from our newest research engineer. Throw in some choice must-reads and an ASR demo, and you’ve got yourself an action-packed newsletter! New Research! Ethical Considerations When Designing an NLG System In the final post of our blog series on Text Style Transfer, we discuss some ethical considerations when working with natural language generation systems, and describe the design of our prototype application: Exploring Intelligent Writing Assistance.
...read more
Sep 8, 2022 · post

Thought experiment: Human-centric machine learning for comic book creation

by Michael Gallaspy · This post has a companion piece: Ethics Sheet for AI-assisted Comic Book Art Generation I want to make a comic book. Actually, I want to make tools for making comic books. See, the problem is, I can’t draw too good. I mean, I’m working on it. Check out these self portraits drawn 6 months apart: Left: “Sad Face”. February 2022. Right: “Eyyyy”. August 2022. But I have a long way to go until my illustrations would be considered professional quality, notwithstanding the time it would take me to develop the many other skills needed for making comic books.
...read more
Aug 18, 2022 · newsletter

CFFL August Newsletter

August 2022 Welcome to the August edition of the Cloudera Fast Forward Labs newsletter. This month we’re thrilled to introduce a new member of the FFL team, share TWO new applied machine learning prototypes we’ve built, and, as always, offer up some intriguing reads. New Research Engineer! If you’re a regular reader of our newsletter, you likely noticed that we’ve been searching for new research engineers to join the Cloudera Fast Forward Labs team.
...read more

Popular posts

Oct 30, 2019 · newsletter
Exciting Applications of Graph Neural Networks
Nov 14, 2018 · post
Federated learning: distributed machine learning with data locality and privacy
Apr 10, 2018 · post
PyTorch for Recommenders 101
Oct 4, 2017 · post
First Look: Using Three.js for 2D Data Visualization
Aug 22, 2016 · whitepaper
Under the Hood of the Variational Autoencoder (in Prose and Code)
Feb 24, 2016 · post
"Hello world" in Keras (or, Scikit-learn versus Keras)

Reports

In-depth guides to specific machine learning capabilities

Prototypes

Machine learning prototypes and interactive notebooks
Notebook

ASR with Whisper

Explore the capabilities of OpenAI's Whisper for automatic speech recognition by creating your own voice recordings!
https://colab.research.google.com/github/fastforwardlabs/whisper-openai/blob/master/WhisperDemo.ipynb
Library

NeuralQA

A usable library for question answering on large datasets.
https://neuralqa.fastforwardlabs.com
Notebook

Explain BERT for Question Answering Models

Tensorflow 2.0 notebook to explain and visualize a HuggingFace BERT for Question Answering model.
https://colab.research.google.com/drive/1tTiOgJ7xvy3sjfiFC9OozbjAX1ho8WN9?usp=sharing
Notebooks

NLP for Question Answering

Ongoing posts and code documenting the process of building a question answering model.
https://qa.fastforwardlabs.com

Cloudera Fast Forward Labs

Making the recently possible useful.

Cloudera Fast Forward Labs is an applied machine learning research group. Our mission is to empower enterprise data science practitioners to apply emergent academic research to production machine learning use cases in practical and socially responsible ways, while also driving innovation through the Cloudera ecosystem. Our team brings thoughtful, creative, and diverse perspectives to deeply researched work. In this way, we strive to help organizations make the most of their ML investment as well as educate and inspire the broader machine learning and data science community.

Cloudera   Blog   Twitter

©2022 Cloudera, Inc. All rights reserved.