PermutationExplainer#

class sdm.explain.PermutationExplainer(num_repeats: int = 5, scoring: Callable[[TableTensor, TableTensor], Tensor | float] | None = None)#

Bases: object

Compute the score decrease from shuffling feature columns from the “Random Forests” paper.

Each column is in turn shuffled across the query rows of a fitted model.

Parameters:
  • num_repeats (int) – The number of shuffles N per column.

  • scoring (Callable[[TableTensor, TableTensor], Tensor | float] | None) – A function scoring(pred, target) that maps the predictions and the targets of the query rows to one number, for which higher is better, e.g., an accuracy or the negative of an error. If None, will use the negative log loss for categorical targets, and the negative mean squared error for numerical targets.

explain(model: ICLModel, x: TableTensor, y: TableTensor, *, generator: Generator | None = None) → TableTensor#

Explain the importance of feature columns.

Parameters:
  • model (ICLModel) – The fitted model.

  • x (TableTensor) – The feature tensor of query examples with shape [..., R, D] with R rows and D columns.

  • y (TableTensor) – The targets of query examples with shape [R, 1].

  • generator (Generator | None) – Pseudorandom number generator used for shuffling.

Returns:

The table of score decreases with shape [..., N, D].

Return type:

TableTensor