2026-10-11
Using LLM with SHAPIQ to Enhance Classification Observability
Premise
This blog post will discuss how I combined SHAPIQ and LLM prompt engineering to create a super intuitive model prediction explanation for an application I built that gives me a prediction on whether I will train tomorrow. Explainability is a key part of this project. A blank number won't incentivize me to train, no matter how close to 100% the train probability is. A confident prediction that makes it clear why tomorrow is a good day to train is a legitimate motivator.
My idea was that if I built a classification model, I could then use SHAP values to highlight the contributors toward that explanation.
Here is the app if you want to check it out before reading
What Are SHAP Values
SHAP is a concept that comes from game theory. The idea is: how would you split the payout (prediction) among the players (features)? To do this, we calculate the marginal contributions of features from the model's average prediction to the predicted probability. It is important to note that SHAP values are different from feature importance. A high (in magnitude) SHAP value doesn't mean that the feature is the most important in the model; it just means that, for this specific prediction, that feature pushed this prediction furthest from the model's average. SHAP is local to a prediction, as opposed to global for the model. The equation is basically base value + Σφ = prediction. It is also important to note that SHAP values are not causal; they just describe what the model is doing.
How to Calculate SHAP for Tree Based Models
The key part of how SHAP is calculated for trees is that in a tree-based model, you can "remove" a feature without retraining. Basically, when you hit a split on a feature that you have "removed," instead of splitting, you just take a weighted average of either side of the split, essentially removing the impact of the feature. Using this process, you can simultaneously evaluate versions of the model on subsets of features, and then take an average of all marginal contributions from different combinations to find the specific SHAP values for different features.
One catch: for a boosted classifier like XGBoost, SHAP values come out in log-odds, not probability. With a logistic objective, each tree's leaves store log-odds increments, so the model's raw output (the margin) is base score + tree₁(x) + ... + tree_T(x), which is the log-odds of the outcome. That's the space where the trees add up, so it's where SHAP values add up too. The margin is an unbounded score, not a probability. To convert it, apply the sigmoid, which inverts the log-odds definition and maps it to 0–100%.
Waterfall Plot
A waterfall plot does a good job illustrating how the model moves from base value to final prediction as a summation of feature contributions.

Here are the log-odds/probability scores from each feature.

SHAPIQ
SHAPIQ is a method of going from feature impact to feature and feature interaction impact. So, basically, if my model has "will it rain" and "will it be cold," the real power comes from when it's rainy and cold, and SHAPIQ will pick up on that.
I use k-SII (k-Shapley Interaction Index) with k=2. Raw Shapley interaction values give each pair a clean score, but they stop summing to the prediction. k-SII fixes that by folding all higher-order interactions into the orders up to k, so base value + main effects + pairwise effects still equals the model's output. With k=1, it reduces to ordinary SHAP. With k=2, main effects are what's left after pairwise interactions are separated out, so they won't match plain SHAP values. That additivity is what lets me draw one waterfall with both feature rows and interaction rows, and hand the LLM a complete accounting of the prediction.
This is a pretty new method introduced in 2024 — here is a citation
Combining SHAPIQ with LLM
I recognized the opportunity to use an LLM to convert this waterfall/SHAPIQ summary into an LLM prompt that can give a pretty conclusive summary of why a decision was made with the model. My initial attempt was alright, but I learned a few things along the way, which I'll talk about here. They can all basically be summed up as "provide context," so I will walk through 3.5 scenarios of me adding more and more context with some simple examples of oversimplified prompts.
Scenario 1
Before: The model says Logan will train because of the variable rain_tomorrow
In this case, I noticed the summary was saying "You are going to train because forecast has rain."
After: The model says Logan will train tomorrow because of variable rain_tomorrow, which has a value of false.
In this case, the model realizes that rain_tomorrow isn't me saying it will rain tomorrow; it's me saying the variable containing information on whether it will rain tomorrow has a value of "No," and that's why it is contributing toward me training.
Scenario 2
Before: The model says Logan won't train tomorrow because of variable trained_seven_days, which has value 5.
In this case, I realized the model has information on the feature impact on the prediction and the value, but it has no visibility into the context of what that means.
After: The model says Logan won't train tomorrow because of variable trained_seven_days, which has value 5; this is above the average for that variable, which is 3, and it is the 75th percentile.
With this information, the LLM knows the feature name, the feature value, and the relative meaning of that variable.
Scenario 3
Before: The model says Logan won't train tomorrow because of variable mileage_chronic_28, which has value 10,000; this is above the average for that variable, which is 3,000, and it is the 75th percentile.
This is informative, but the LLM doesn't inherently know what mileage_chronic_28 actually is, so the last step I did was defining each of my features.
After: The model says Logan won't train tomorrow because of variable mileage_chronic_28, which has value 10,000; this is above the average for that variable, which is 3,000, and it is the 75th percentile. This feature represents how many miles Logan has biked in the last 28 days.
Scenario 3.5
I also took some measures to inform the LLM on units for things like mileage.
I essentially end up building a chunk of information for the LLM that contains features, values, and distribution statistics for each feature in the top X highest-magnitude SHAPIQ values.
I include a visualization in my app which describes this well.

In the repo this looks like a dictionary.
FEATURE_INFO: dict[str, FeatureInfo] = {
"acute_load_7": FeatureInfo(
phrase: "recent training load in your legs",
definition: "short-term training load: 7-day exponentially weighted average of daily total Strava Relative Effort (a heart-rate based score of how hard a day was)",
unit:"effort points/day"),
...
}Here is a prompt example
I have a model that predicts whether an athlete will train tomorrow based on various factors.
I want you to make a clean, concise summary of the prediction based on the data provided.
Tell the athlete what we think will occur tomorrow based on the prediction along with why based on the top contributing factors.
Each factor's meaning only names the variable, not its state (value=0 for 'rain in the forecast' means NO rain). Describe tomorrow's actual condition from the value, units and definition, and never claim anything they contradict. A positive contribution from a low value means the low value is helping.
Use a sassy tone
HERE IS YOUR DATA INPUT:
prediction: train
probability_to_train: 76.2%
predicted_effort: 41.4 (relative-effort units)
top_contributing_factors (feature, meaning, signed contribution toward training):
- dow_train_rate (variable meaning: regular train rate for this day of the week): value=0.321 fraction 0-1 (typical 0.172 fraction 0-1, 96% of history is at or below); definition: share of past days with this same weekday on which the athlete trained; signed_contribution=+0.296 (helping the training call)
- trained_days_7 (variable meaning: how often you've trained this past week): value=5.0 active days (typical 2.0 active days, 97% of history is at or below); definition: number of distinct ACTIVE DAYS in the last 7 days; NOT a workout count, several workouts on one day count once; signed_contribution=+0.201 (helping the training call)
- month_train_rate (variable meaning: regular train rate for this month): value=0.258 fraction 0-1 (typical 0.145 fraction 0-1, 65% of history is at or below); definition: share of past days in this calendar month (across years) on which the athlete trained; signed_contribution=+0.196 (helping the training call)
- forecast_precip_probability (variable meaning: rain in the forecast): value=0.0 % of hours (typical 8.333 % of hours, 44% of history is at or below); definition: share of tomorrow's 24 hours with any precipitation (0 = fully dry day, 100 = rain all day); signed_contribution=+0.185 (helping the training call)
- days_since_last_hard (variable meaning: time since your last hard effort): value=2.0 days (typical 4.0 days, 39% of history is at or below); definition: days since the last day whose Relative Effort reached the athlete's 'hard day' cutoff; signed_contribution=+0.140 (helping the training call)
- chronic_load_28 (variable meaning: longer-term fitness base): value=42.678 effort points/day (typical 21.505 effort points/day, 90% of history is at or below); definition: long-term fitness/training load: 28-day exponentially weighted average of daily total Strava Relative Effort; signed_contribution=+0.125 (helping the training call)
- trained_days_30 (variable meaning: your training frequency over the past month): value=17.0 active days (typical 8.0 active days, 96% of history is at or below); definition: number of distinct ACTIVE DAYS in the last 30 days; NOT a workout count, several workouts on one day count once; signed_contribution=-0.106 (hurting the training call)
- forecast_temp_high (variable meaning: the temp high forecast): value=64.58 °F (typical 58.28 °F, 64% of history is at or below); definition: tomorrow's forecast daily high temperature; signed_contribution=+0.103 (helping the training call)
- forecast_temp_high_vs_seasonal (variable meaning: how the temp high compares to normal for this time of year): value=0.83 °F (typical 0.244 °F, 53% of history is at or below); definition: forecast high minus the historical average high for this time of year; positive = warmer than normal; signed_contribution=+0.087 (helping the training call)
- month_train_rate × forecast_temp_high (variable meaning: interaction between regular train rate for this month and the temp high forecast): month_train_rate value=0.258 fraction 0-1 (typical 0.145 fraction 0-1, 65% of history is at or below); forecast_temp_high value=64.58 °F (typical 58.28 °F, 64% of history is at or below); definition: month_train_rate: share of past days in this calendar month (across years) on which the athlete trained; forecast_temp_high: tomorrow's forecast daily high temperature; signed_contribution=+0.052 (helping the training call)Response:
Lace up your sneakers, because the data says you're training tomorrow. There is a **76.2% chance** you'll be out there, with a predicted target effort of **41.4 relative-effort units**.
Here is why you don't really have an excuse:
* **Zero Weather Excuses:** Tomorrow's forecast is showing a **0% chance of rain** and a gorgeous high of **64.6°F** (slightly warmer than normal). Nature is basically rolling out the red carpet for you.
* **It's Your Habitual Day:** You historically train far more often on this day of the week (a 32% train rate vs. your usual 17% benchmark), and this month is typically one of your higher-activity months anyway.
* **You've Got the Momentum:** You've hit **5 active days in the last 7**, your 28-day fitness base is sitting high at **42.7 effort points/day**, and it's been **2 full days since your last hard effort**—so your legs are rested enough to handle it.
* **The Lone Hater:** Having **17 active days over the last 30** is pulling slightly toward taking a break, but that minor fatigue signal isn't enough to drag you to the couch.
See you out there tomorrow. No excuses!Here is the app again if I have peaked your interest.