Skip to content

Exact Shapley, anchors, diverse counterfactuals, influence and the audit

Exact Shapley values for small models, rules that hold a prediction in place, several ways to change it, the training rows behind it, and a check of whether an explanation is faithful to the model at all.

Advanced ~12 min7 steps

What runs in CodeSplash

You will be able to

  • Know when exact Shapley values replace KernelSHAP
  • Read an anchor's precision, its lower bound and its coverage
  • Use diverse counterfactuals and influence to answer "what would change it" and "what taught it this"
  • Read the deletion check and explainer agreement before trusting an explanation

Read first

01

Four more questions

Read

The Explain tab in Predict adds these to the explainers in the previous lesson. Each answers its own question.

QuestionExplainerCheck its answer with
Exactly how much did each feature add?Exact ShapleyExact Shapley valuesShapley values computed from every combination of features, so they add up exactly to each prediction minus the average.The values add up to the score minus the average
What rule keeps this prediction?AnchorsAnchorA short rule built from a row's own values that keeps its prediction for most rows that satisfy it.Precision, its lower 95% bound, Coverage
What different changes would flip it?Diverse counterfactualsDiverse counterfactualsSeveral different changes that would each move a prediction across its target, chosen to be close to the row and far apart.Each option's Score after and Distance
Which training rows taught it this?Training rows behind itInfluence (training rows)How much a prediction would move if one training row were left out and the model refitted.Effect and Leverage
02

Exact Shapley values

Read

KernelSHAP estimates Shapley values from a sample of feature combinations. With few features you don't need to estimate: Exact Shapley evaluates all 2^p combinations against the same background rows. With 8 features that is 256 combinations per row. With 12 it is 4,096. Above 12, CodeSplash says so and points you back to KernelSHAP.

Use the exact values as a reference. If KernelSHAP's mean |φ| differs from the exact values by more than a few percent, raise its coalitions or background rows. The audit below flags that gap.

03

Anchors

Read

An anchor is a short rule built from the row's own values, such as glucose > 140 AND age > 29, that keeps the prediction for most training rows satisfying it.

  • Precision is the share of training rows satisfying the rule that get the same prediction.
  • Precision, lower 95% is the Wilson lower bound. A rule supported by 12 rows can show 100% precision with a lower bound near 75%.
  • Coverage is the share of all training rows the rule applies to. Short rules cover more rows.

The search adds the condition that raises precision most until it reaches the target (95% by default).

04

Diverse counterfactuals

Read

The greedy counterfactual gives one smallest change. Diverse counterfactuals give several different ones, in the style of DiCE. CodeSplash draws random candidate changes and keeps those that reach the target. It picks the closest first, then the ones farthest from those already picked, and drops any change an option doesn't need. Options let a person choose a change they can actually make. Mark what they can't change under Never change.

05

Training rows behind a prediction

Read

For linear and logistic models, the explainer shows which training rows moved each prediction most. Effect is how much the prediction would drop if that row were left out and the model refitted. It is exact for least squares and a one-step approximation for logistic regression. Rows with high Leverage (unusual feature values) and large residuals matter most. A single row with a huge effect is worth opening: it may be a data error.

06

Is the explanation faithful?

Read

Check the explanations runs a deletion check. For a few rows it removes features in the order the attributions rank them, and again in a random order. A removed feature takes the background rows' values.

Deletion check (explanation faithfulness)Do the features an explanation ranks first really move the prediction the most?
View data
share of features removedshare of the score leftorder
01By TreeSHAP
0.12500.5920By TreeSHAP
0.25000.2950By TreeSHAP
0.37500.2060By TreeSHAP
0.50000.1460By TreeSHAP
0.62500.0740By TreeSHAP
0.75000.0570By TreeSHAP
0.87500.0330By TreeSHAP
10By TreeSHAP
01Random
0.12500.8300Random
0.25000.6840Random
0.37500.6350Random
0.50000.5620Random
0.62500.4550Random
0.75000.2070Random
0.87500.1050Random
10Random

If the ranking is faithful, the score falls faster when features go in ranked order. Faithfulness is the random curve's area minus the attribution curve's area. Positive is good; near zero means the ranking tells you little about this model.

07

Do the explainers agree?

Read

The audit also compares the explainers you ran. Spearman's ρ between their feature rankings and the overlap of their top three show how alike they are. Permutation importance and SHAP answer different questions: shuffling a feature versus its share of each prediction. Low agreement is a reason to look at correlated features, not proof that one of them is wrong.

Check yourself

A model has 9 features. KernelSHAP's mean |φ| for income is 0.31 and exact Shapley's is 0.22. What should you do?

Show the answer

Answer: b

With 9 features exact enumeration is cheap (512 combinations). KernelSHAP is an estimate of the same values, so a large gap means its sample was too small.

Check yourself

An anchor shows precision 100%, lower 95% 0.76 and coverage 0.02. How should you read it?

Show the answer

Answer: b

Coverage 0.02 means the rule applies to 2% of training rows. The Wilson lower bound shows how little those rows can prove.

Check yourself

Why ask for several counterfactuals instead of the single smallest change?

Show the answer

Answer: a

Counterfactuals describe the model's decision boundary. Diversity is about choice, not causation.

Check yourself

One training row has an effect of +0.18 on a prediction of 0.62 from a logistic model. What does that mean?

Show the answer

Answer: a

Influence traces a prediction back to the rows that taught it. For logistic regression it is a one-step approximation of the refit.

Check yourself

The deletion check reports faithfulness 0.01 for KernelSHAP on a model with 6 features. What does it tell you?

Show the answer

Answer: b

Faithfulness compares the attribution's deletion curve with a random order's. A gap near zero means the ranking isn't tracking what moves the prediction, sometimes because correlated features share the credit.

Concepts in this lesson