Lesson 3 of 6 Evaluating ML Models

Explaining Predictions with SageMaker Clarify

This lesson explains how SageMaker Clarify provides model-agnostic explanations that show why a model made a prediction, for regulated decisions, debugging and trust.

Learning outcomes

After completing this lesson, you will be able to:

  • Interpret SHAP values for a prediction.
  • Run a Clarify explainability job with a baseline.
  • Monitor feature attribution drift in production.

SHAP values

Clarify uses SHAP (SHapley Additive exPlanations), based on Shapley values from game theory. For one prediction, each feature receives a value showing how much it pushed the prediction up or down from a baseline (a reference input, such as the average record). The values add up to the difference between the prediction and the baseline prediction, so explanations are consistent. Averaging absolute SHAP values over many predictions gives global feature importance.

The following diagram shows how SHAP contributions build up the default probability predicted for a declined loan applicant.

SHAP values for the declined applicant. From a baseline default probability of 0.08, debt-to-income adds 0.19, missed payments add 0.11 and a short credit history adds 0.06, while income subtracts 0.02, giving the prediction of 0.42. The contributions sum to the difference from the baseline, so the decline letter can list the three main reasons.
The scenario is illustrative.
Fill in the value

Add up the SHAP values

Exam skills 2.3.4

Use the additive property of SHAP values to work out a prediction.

Log in to try this activity Interactive activities are free with an account.

Running Clarify

A Clarify processing job takes the dataset, a model (deployed to a temporary shadow endpoint) and a configuration with the baseline and the number of samples, and writes a report with global importance, per-record SHAP values and partial dependence plots (how the prediction changes as one feature varies). Clarify also explains NLP models (importance of tokens or phrases) and computer vision models (image regions). Online explainability returns SHAP values with each real-time prediction from an endpoint.

Explainability in production

Explanations matter after deployment as well as before it. SageMaker Model Monitor can run Clarify on data captured from an endpoint to detect feature attribution drift: a change over time in which features drive the model's predictions. Such a change signals that the model's behaviour has shifted, often because the input data has changed, even when accuracy has not yet visibly dropped.

Explanations and their analysis can be documented in SageMaker Model Cards, which give auditors and stakeholders a record of how the model reaches its decisions. The following table summarises the explanation types.

ExplanationAnswersClarify feature
Local SHAP valuesWhy this prediction?Per-record SHAP, online explainability
Global importanceWhich features matter overall?Mean absolute SHAP
Partial dependenceHow does the prediction change with one feature?PDP in the report
Attribution driftHas feature importance changed in production?Model Monitor with Clarify
True or false

Explanations in production

Exam skills 2.3.4 · 4.1.3

Check how explanations work for a deployed model.

Log in to try this activity Interactive activities are free with an account.
Worked example

Explaining a declined loan

A lender must give each declined applicant the main reasons. The model is XGBoost on an endpoint, and the baseline is the average approved applicant.

Prediction: P(default) = 0.42  (baseline 0.08)
Feature                     SHAP contribution
debt_to_income = 0.61       +0.19
missed_payments_12m = 3     +0.11
credit_history_years = 1    +0.06
income = 85,000             -0.02
Sum of contributions = +0.34 = 0.42 - 0.08

The decline letter lists high debt-to-income ratio, recent missed payments and short credit history. Enabling online explainability on the endpoint returns these values with each prediction, so no separate batch job is needed for each applicant.

Check yourself

How is overall feature importance calculated from SHAP values?

Show answer

As the mean absolute SHAP value of each feature across predictions.

Exam Tips

Remember for the exam

  • Why this prediction: Clarify SHAP values.
  • Overall feature importance: mean absolute SHAP values.
  • SHAP values are relative to a baseline input.
  • Explanations with real-time predictions: Clarify online explainability.
  • Feature importance changing in production: feature attribution drift monitor.