Classes to build objects to better interpret predictions of a model

class Interpretation[source]

Interpretation(learn:Learner, dl:DataLoader, losses:TensorBase, act=None)

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

Type Default Details
learn Learner No Content
dl DataLoader DataLoader to run inference over
losses TensorBase Losses calculated from dl
act None Activation function for prediction

Interpretation is a helper base class for exploring predictions from trained models. It can be inherited for task specific interpretation classes, such as ClassificationInterpretation. Interpretation is memory efficient and should be able to process any sized dataset, provided the hardware could train the same model.

Interpretation.from_learner[source]

Interpretation.from_learner(learn, ds_idx:int=1, dl:DataLoader=None, act=None)

Construct interpretation object from a learner

Type Default Details
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 None Override default or set prediction activation function

Interpretation.top_losses[source]

Interpretation.top_losses(k:(int, None)=None, largest:bool=True, items:bool=False)

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

Type Default Details
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

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.

Interpretation.plot_top_losses[source]

Interpretation.plot_top_losses(k:(int, list), largest:bool=True, **kwargs)

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

Type Default Details
k (int, list) Number of losses to plot
largest bool True Sort losses by largest or smallest
kwargs No Content

To plot the first 9 top losses:

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

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

interp.plot_top_losses(range(7,16))

Interpretation.show_results[source]

Interpretation.show_results(idxs:list, **kwargs)

Show predictions and targets of idxs

Type Default Details
idxs list Indices of predictions and targets
kwargs No Content

Like Learner.show_results, except can pass desired index or indicies for item(s) to show results from.

class ClassificationInterpretation[source]

ClassificationInterpretation(learn:Learner, dl:DataLoader, losses:TensorBase, act=None) :: Interpretation

Interpretation methods for classification models.

Type Default Details
learn Learner No Content
dl DataLoader DataLoader to run inference over
losses TensorBase Losses calculated from dl
act None Activation function for prediction

ClassificationInterpretation.confusion_matrix[source]

ClassificationInterpretation.confusion_matrix()

Confusion matrix as an np.ndarray.

ClassificationInterpretation.plot_confusion_matrix[source]

ClassificationInterpretation.plot_confusion_matrix(normalize:bool=False, title:str='Confusion matrix', cmap:str='Blues', norm_dec:int=2, plot_txt:bool=True, **kwargs)

Plot the confusion matrix, with title and using cmap.

Type Default Details
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 No Content

ClassificationInterpretation.most_confused[source]

ClassificationInterpretation.most_confused(min_val=1)

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

class SegmentationInterpretation[source]

SegmentationInterpretation(learn:Learner, dl:DataLoader, losses:TensorBase, act=None) :: Interpretation

Interpretation methods for segmentation models.

Type Default Details
learn Learner No Content
dl DataLoader DataLoader to run inference over
losses TensorBase Losses calculated from dl
act None Activation function for prediction