explainability.SeldonExplainer¶
- class SeldonExplainer(estimator, background, *, index='k-SII', max_order=2, class_index=None, imputer='marginal', max_background_samples=100, feature_names=None, random_state=None, verbose=False)¶
Explain predictions of a fitted Seldon estimator with Shapley values.
Wraps
shapiq.TabularExplainerto provide both local (per-instance) and global (dataset-level) explanations. For classifiers the explanations are computed on a single class probability selected byclass_index; for regressors they are computed on the predicted value.- Parameters:
estimator (SeldonClassifier, SeldonRegressor or Seldon) – A fitted Seldon estimator. The
Seldonwrapper is accepted and unwrapped to its inner estimator.background (array-like of shape (n_samples, n_features)) – Reference data used to impute the values of features that are “absent” from a coalition. Typically (a subset of) the training data. To bound cost and latency, it is subsampled to
max_background_samplesrows.index (str, default="k-SII") –
Interaction index to estimate. Common choices:
"SV": plain Shapley values (no interactions,max_orderforced to 1)."k-SII": k-order Shapley Interaction Index (default)."FSII": Faithful Shapley Interaction Index.
Any index supported by
shapiq.TabularExplaineris accepted.max_order (int, default=2) – Maximum interaction order to estimate.
1yields feature attributions only;2additionally captures pairwise interactions. Ignored (forced to1) whenindex="SV".class_index (int, optional) – For classification, the index into
classes_whose probability is explained. Defaults to the positive class (1) for binary targets; for multiclass targets it defaults to1with a warning — pass an explicit value to choose the class of interest. Ignored for regression.imputer (str, default="marginal") – Imputation strategy for absent features, forwarded to shapiq (e.g.
"marginal","conditional","baseline").max_background_samples (int, default=100) – Maximum number of background rows to keep. Larger background sets give more faithful imputation but increase the size of every remote request.
feature_names (sequence of str, optional) – Names used when plotting. Defaults to the estimator’s
column_namesif set, otherwiseNone.random_state (int, optional) – Seed controlling background subsampling and shapiq’s sampling.
verbose (bool, default=False) – Forwarded to shapiq to show a progress bar during estimation.
- Variables:
task_type (str) –
"classification"or"regression", copied from the estimator.class_index (int or None) – Resolved class index being explained (classification only).
feature_names (list of str or None) – Feature names used for plotting.
background (ndarray of shape (n_kept, n_features)) – The (subsampled) background data passed to shapiq.
See also
neuralk.explainability.GlobalExplanationResult of
explain_global.
Examples
>>> explainer = SeldonExplainer(clf, background=X_train, index="k-SII") >>> iv = explainer.explain(X_test[0]) >>> iv.plot_force(feature_names=explainer.feature_names)