﻿# Interpretation of Predictions


<!-- WARNING: THIS FILE WAS AUTOGENERATED! DO NOT EDIT! -->

------------------------------------------------------------------------

<a
href="https://github.com/fastai/fastai/blob/main/fastai/interpret.py#L26"
target="_blank" style="float:right; font-size:smaller">source</a>

### Interpretation

``` python
def Interpretation(
    learn:Learner, dl:DataLoader, # `DataLoader` to run inference over
    losses:TensorBase, # Losses calculated from `dl`
    act:NoneType=None, # Activation function for prediction
):
```

*Interpretation base class, can be inherited for task specific
Interpretation classes*

[`Interpretation`](https://docs.fast.ai/interpret.html#interpretation)
is a helper base class for exploring predictions from trained models. It
can be inherited for task specific interpretation classes, such as
[`ClassificationInterpretation`](https://docs.fast.ai/interpret.html#classificationinterpretation).
[`Interpretation`](https://docs.fast.ai/interpret.html#interpretation)
is memory efficient and should be able to process any sized dataset,
provided the hardware could train the same model.

<div>

> **Note**
>
> [`Interpretation`](https://docs.fast.ai/interpret.html#interpretation)
> is memory efficient due to generating inputs, predictions, targets,
> decoded outputs, and losses for each item on the fly, using batch
> processing where possible.

</div>

------------------------------------------------------------------------

<a
href="https://github.com/fastai/fastai/blob/main/fastai/interpret.py#L47"
target="_blank" style="float:right; font-size:smaller">source</a>

### Interpretation.from_learner

``` python
def from_learner(
    learn, # Model used to create interpretation
    ds_idx:int=1, # Index of `learn.dls` when `dl` is None
    dl:DataLoader=None, # `Dataloader` used to make predictions
    act:NoneType=None, # Override default or set prediction activation function
):
```

*Construct interpretation object from a learner*

------------------------------------------------------------------------

<a
href="https://github.com/fastai/fastai/blob/main/fastai/interpret.py#L59"
target="_blank" style="float:right; font-size:smaller">source</a>

### Interpretation.top_losses

``` python
def top_losses(
    k:int | None=None, # Return `k` losses, defaults to all
    largest:bool=True, # Sort losses by largest or smallest
    items:bool=False, # Whether to return input items
):
```

*`k` largest(/smallest) losses and indexes, defaulting to all losses.*

With the default of `k=None`, `top_losses` will return the entire
dataset’s losses. `top_losses` can optionally include the input items
for each loss, which is usually a file path or Pandas `DataFrame`.

------------------------------------------------------------------------

<a
href="https://github.com/fastai/fastai/blob/main/fastai/interpret.py#L69"
target="_blank" style="float:right; font-size:smaller">source</a>

### Interpretation.plot_top_losses

``` python
def plot_top_losses(
    k:int | collections.abc.MutableSequence, # Number of losses to plot
    largest:bool=True, # Sort losses by largest or smallest
    **kwargs
):
```

*Show `k` largest(/smallest) preds and losses. Implementation based on
type dispatch*

To plot the first 9 top losses:

``` python
interp = Interpretation.from_learner(learn)
interp.plot_top_losses(9)
```

Then to plot the 7th through 16th top losses:

``` python
interp.plot_top_losses(range(7,16))
```

------------------------------------------------------------------------

<a
href="https://github.com/fastai/fastai/blob/main/fastai/interpret.py#L89"
target="_blank" style="float:right; font-size:smaller">source</a>

### Interpretation.show_results

``` python
def show_results(
    idxs:list, # Indices of predictions and targets
    **kwargs
):
```

*Show predictions and targets of `idxs`*

Like
[`Learner.show_results`](https://docs.fast.ai/learner.html#learner.show_results),
except can pass desired index or indicies for item(s) to show results
from.

------------------------------------------------------------------------

<a
href="https://github.com/fastai/fastai/blob/main/fastai/interpret.py#L101"
target="_blank" style="float:right; font-size:smaller">source</a>

### ClassificationInterpretation

``` python
def ClassificationInterpretation(
    learn:Learner, dl:DataLoader, # `DataLoader` to run inference over
    losses:TensorBase, # Losses calculated from `dl`
    act:NoneType=None, # Activation function for prediction
):
```

*Interpretation methods for classification models.*

------------------------------------------------------------------------

<a
href="https://github.com/fastai/fastai/blob/main/fastai/interpret.py#L114"
target="_blank" style="float:right; font-size:smaller">source</a>

### ClassificationInterpretation.confusion_matrix

``` python
def confusion_matrix():
```

*Confusion matrix as an `np.ndarray`.*

------------------------------------------------------------------------

<a
href="https://github.com/fastai/fastai/blob/main/fastai/interpret.py#L123"
target="_blank" style="float:right; font-size:smaller">source</a>

### ClassificationInterpretation.plot_confusion_matrix

``` python
def plot_confusion_matrix(
    normalize:bool=False, # Whether to normalize occurrences
    title:str='Confusion matrix', # Title of plot
    cmap:str='Blues', # Colormap from matplotlib
    norm_dec:int=2, # Decimal places for normalized occurrences
    plot_txt:bool=True, # Display occurrence in matrix
    **kwargs
):
```

*Plot the confusion matrix, with `title` and using `cmap`.*

------------------------------------------------------------------------

<a
href="https://github.com/fastai/fastai/blob/main/fastai/interpret.py#L157"
target="_blank" style="float:right; font-size:smaller">source</a>

### ClassificationInterpretation.most_confused

``` python
def most_confused(
    min_val:int=1
):
```

*Sorted descending largest non-diagonal entries of confusion matrix
(actual, predicted, \# occurrences*

------------------------------------------------------------------------

<a
href="https://github.com/fastai/fastai/blob/main/fastai/interpret.py#L173"
target="_blank" style="float:right; font-size:smaller">source</a>

### SegmentationInterpretation

``` python
def SegmentationInterpretation(
    learn:Learner, dl:DataLoader, # `DataLoader` to run inference over
    losses:TensorBase, # Losses calculated from `dl`
    act:NoneType=None, # Activation function for prediction
):
```

*Interpretation methods for segmentation models