LOCOExplainer#
- class sdm.explain.LOCOExplainer(scoring: Callable[[TableTensor, TableTensor], Tensor | float] | None = None)#
Bases:
objectCompute the leave-one-covariate-out (LOCO) importance of feature columns, also known as leave-one-feature-out (LOFO) importance, from the “Distribution-Free Predictive Inference For Regression” paper.
Each column is in turn dropped from both the in-context and the query examples, so that the model predicts as if it had never seen it. The model is called once with all columns and once without each column, and the importance of a column is the score decrease without it.
- Parameters:
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. IfNone, will use the negative log loss for categorical targets, and the negative mean squared error for numerical targets.
- explain(model: ICLModel, x_context: TableTensor, y_context: TableTensor, x_query: TableTensor, y_query: TableTensor, **kwargs: Any) TableTensor#
Explain the importance of feature columns.
- Parameters:
model (ICLModel) – The model.
x_context (TableTensor) – The feature tensor of in-context examples with shape
[..., R_context, D]withR_contextrows andDcolumns.y_context (TableTensor) – The targets of in-context examples with shape
[R_context, 1].x_query (TableTensor) – The feature tensor of query examples with shape
[..., R_query, D]withR_queryrows andDcolumns.y_query (TableTensor) – The targets of query examples with shape
[R_query, 1].kwargs (Any) – Additional keyword arguments passed to the model call.
- Returns:
The table of score decreases with shape
[..., 1, D].- Return type: