> ## Documentation Index
> Fetch the complete documentation index at: https://docs.tabsutra.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Explanations

> Which inputs drove a prediction, and by how much.

Any prediction can come with an explanation. The explanation lists the inputs that moved the prediction, with the size and the direction of each effect. You can use it to check that the model relies on sensible inputs, to answer questions from the business, and to give reasons for a decision, such as the reason codes of a declined credit application.

## Ask for an explanation

Add `"explain": true` to any prediction request: `/v1/predict`, `/v1/fill`, `/v1/forecast`, a database prediction or a task described in words. By default the ten largest effects of each prediction are returned. Change this with `explain_top`.

```python theme={null}
scored = requests.post(f"{API}/v1/predict", headers=HEADERS, json={
    "context_id": context_id, "rows": records(new),
    "explain": True, "explain_top": 5, "explain_class": "yes",
}).json()
```

## What an explanation holds

```json theme={null}
{
  "id": "A2001",
  "label": "no",
  "probabilities": {"no": 0.79, "yes": 0.21},
  "explanation": {
    "of": "probability of yes",
    "baseline": 0.06,
    "prediction": 0.21,
    "contributions": [
      {"input": "bureau_score", "value": 688, "effect": 0.07},
      {"input": "enquiries_6m", "value": 4, "effect": 0.05},
      {"input": "monthly_debt_payments", "value": 1250, "effect": 0.03},
      {"input": "employment", "value": "self-employed", "effect": 0.02},
      {"input": "income", "value": 3100, "effect": -0.01}
    ],
    "rest": -0.01
  }
}
```

* `of` says which number is explained. For a regression or a forecast, it is the mean. For a classification, it is the probability of the class in `explain_class`. Without `explain_class`, it is the probability of the predicted label.
* `baseline` is the average prediction over the context. It is where a row would land if it told the model nothing.
* Each contribution gives an input, the row's value for it, and its effect. A positive effect pushes the prediction up, and a negative effect pushes it down.
* `rest` is the total effect of the inputs not listed.

The baseline, the listed effects and `rest` add up to the prediction.

## What counts as an input

An input is something you would recognise in your own data.

| Data | Inputs |
| - | - |
| A table | Each column. A text, image or embedding column counts as one input, not as its numbers. |
| Sequences | Each column of the row, the earlier rows of its group as one input, and the answers known before it. |
| A database | Each column of the entity and of the tables it points at, and for each table of events: its counts, and its latest events. The entity's earlier answers are one more input. |
| A forecast | The past values of the series, the time of year, week and day, and each other column you send. |
| A recommendation | The user's past links, what similar users picked, the related tables, and the item's and the user's own columns. |

## Importance over many rows

The report of a request with explanations has `importance`. For each input, it gives the average size of its effect over the rows predicted. Use it to see which inputs matter most across a portfolio, a region or a period.

```json theme={null}
"importance": [
  {"input": "bureau_score", "mean_absolute_effect": 0.041},
  {"input": "enquiries_6m", "mean_absolute_effect": 0.022},
  {"input": "employment", "mean_absolute_effect": 0.013}
]
```

## Reason codes

For a credit decision, ask for the probability of the bad outcome with `explain_class`, and take the inputs with the largest positive effects as the reasons. Map each input to the wording your policy uses, such as "number of recent credit enquiries".

## Reading explanations with care

* An explanation describes how the model used the inputs for this prediction. It does not say that an input causes the outcome.
* When two inputs carry the same information, such as a total and its parts, the effect can be shared between them. Look at such inputs together.
* Explanations take longer to compute than the predictions alone. Ask for them where you need them, for example on the rows you decline or review.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.