facet.explanation.base.BaseExplainer#
- class facet.explanation.base.BaseExplainer(*args, **kwargs)[source]#
Abstract base class of SHAP explainers, providing stubs for methods used by FACET but not consistently supported by class
shap.Explainer
across different versions of the shap package.Provides unified support for the old and new explainer APIs:
The old API uses methods
shap_values()
andshap_interaction_values()
to compute SHAP values and interaction values, respectively. They return numpy arrays for single-output or single-class models, and lists of numpy arrays for multi-output or multi-class models.The new API introduced in
shap
0.36 makes explainer objects callable; direct calls to an explainer object return anExplanation
object that contains the SHAP values and interaction values. For multi-output or multi-class models, the array has an additional dimension for the outputs or classes as the last axis.
As of
shap
0.36, the old API is deprecated for the majority of explainers while theshap.KernelExplainer
still uses the old API exclusively inshap
0.41. We remedy this by adding support for both APIs to all explainers created through anExplainerFactory
object.- Bases
Explainer
- Metaclasses
- Parameters
Method summary
See
shap.explainers.Explainer.explain_row()
See
shap.explainers.Explainer.load()
See
shap.explainers.Explainer.save()
Estimate the SHAP interaction values for a set of samples.
Estimate the SHAP values for a set of samples.
See
shap.explainers.Explainer.supports_model_with_masker()
Attribute summary
True
if the explainer supports interaction effects,False
otherwise.Definitions
- __call__(*args, max_evals='auto', main_effects=False, error_bounds=False, batch_size='auto', outputs=None, silent=False, **kwargs)#
See
shap.explainers.Explainer.__call__()
- explain_row(*row_args, max_evals, main_effects, error_bounds, outputs, silent, **kwargs)#
See
shap.explainers.Explainer.explain_row()
- classmethod load(in_file, model_loader=<bound method Model.load of <class 'shap.models.Model'>>, masker_loader=<bound method Serializable.load of <class 'shap.maskers.Masker'>>, instantiate=True)#
See
shap.explainers.Explainer.load()
- save(out_file, model_saver='.save', masker_saver='.save')#
See
shap.explainers.Explainer.save()
- shap_interaction_values(X, y=None, **kwargs)[source]#
Estimate the SHAP interaction values for a set of samples.
- Parameters
X (
Union
[ndarray
[Any
,dtype
[Any
]],DataFrame
,Pool
]) – matrix of samples (# samples x # features) on which to explain the model’s outputy (
Union
[ndarray
[Any
,dtype
[Any
]],Series
,None
]) – array of label values for each sample, used when explaining loss functions (optional)kwargs (
Any
) – additional arguments specific to the explainer implementation
- Return type
Union
[ndarray
[Any
,dtype
[float64
]],List
[ndarray
[Any
,dtype
[float64
]]]]- Returns
SHAP values as an array of shape \((n_\mathrm{observations}, n_\mathrm{features}, n_\mathrm{features})\); a list of such arrays in the case of a multi-output model
- shap_values(X, y=None, **kwargs)[source]#
Estimate the SHAP values for a set of samples.
- Parameters
X (
Union
[ndarray
[Any
,dtype
[Any
]],DataFrame
,Pool
]) – matrix of samples (# samples x # features) on which to explain the model’s outputy (
Union
[ndarray
[Any
,dtype
[Any
]],Series
,None
]) – array of label values for each sample, used when explaining loss functions (optional)kwargs (
Any
) – additional arguments specific to the explainer implementation
- Return type
Union
[ndarray
[Any
,dtype
[float64
]],List
[ndarray
[Any
,dtype
[float64
]]]]- Returns
SHAP values as an array of shape (n_observations, n_features); a list of such arrays in the case of a multi-output model
- static supports_model_with_masker(model, masker)#
See
shap.explainers.Explainer.supports_model_with_masker()