shap_linear – Linear SHAP – closed-form Shapley values for linear models.#
Back to op axis | Back to L7 | Browse all options
Operational op under axis
op, sub-layerL7_A_importance_dag_body, layerl7. Standalone callable:mf.functions.shap_linear_importance.
Function signature#
mf.functions.shap_linear_importance(
result: FitResultBase,
X: np.ndarray | pd.DataFrame,
) -> SHAPImportanceResult
Parameters#
name |
type |
default |
constraint |
description |
|---|---|---|---|---|
|
|
— |
— |
Fitted result object exposing ._model (the raw sklearn estimator). Returned by any L4 standalone callable such as mf.functions.ridge_fit, mf.functions.random_forest_fit, etc. |
|
`np.ndarray |
pd.DataFrame` |
— |
— |
Returns#
SHAPImportanceResult — frozen dataclass with fit results.
Attribute |
Type |
Description |
|---|---|---|
|
|
SHAP values, shape (n_samples, n_features). |
|
|
SHAP base value (expected model output). |
|
|
Feature names. |
|
|
Explainer used (LinearExplainer / KernelExplainer). |
|
|
Table of mean absolute SHAP values. |
Behavior#
For a fitted linear model f(x) = β'x + b, the SHAP value for feature j reduces to β_j (x_j - E[x_j]). Uses the training-sample mean as the reference. Available for every linear L4 family.
When to use
Linear models when the SHAP per-row decomposition is needed (otherwise model_native_linear_coef suffices).
In recipe context#
Set params.op = "shap_linear" in the relevant layer to activate this op within a recipe:
# Layer L7 recipe fragment
params:
op: shap_linear
References#
macroforecast design Part 3, L7: ‘every importance op produces (table, figure) pairs; the L7.B sub-layer governs export shape.’
Lundberg & Lee (2017) ‘A Unified Approach to Interpreting Model Predictions’, NeurIPS 30: 4765-4774.