Explainer Base¶
- class xaicompare.adapters.explainers.explainer_base.ExplainerAdapter(model_adapter: Any, config: Dict[str, Any] | None = None)[source]¶
Bases:
ABCBase class that standardizes how different explainers are called and what they return.
Concrete implementations (e.g., SHAP Tree for XGBoost/LightGBM, SHAP Kernel for generic models, LIME-Text, etc.) should subclass this.
- Contract:
- global_importance(X, rows_limit) -> (mean_abs, feature_names)
mean_abs: 1D np.ndarray of length n_features (mean absolute importance)
feature_names: List[str] of length n_features (ordering aligns with mean_abs)
- local_explanations(X_row) -> 1D np.ndarray of length n_features (signed values)
X_row represents a single sample (shape (1, …)); caller may pass a slice X[i:i+1]
- _abc_impl = <_abc._abc_data object>¶
- abstractmethod global_importance(x, rows_limit: int = 200) Tuple[ndarray, List[str]][source]¶
Compute a global importance estimate (typically mean
|contribution|) in a memory-safe way across up to rows_limit rows of X.- Returns:
mean_abs (np.ndarray) – 1D array of length n_features with mean absolute importance per feature.
feature_names (List[str]) – The feature names in the same order as ‘mean_abs’.
- abstractmethod local_explanations(x_row) ndarray[source]¶
Explain a single row. Should return a vector of signed contributions whose length matches the feature space (n_features).
Notes
Implementations may aggregate across classes if multi-class (e.g. sum over classes).
If there is a bias term, do NOT return it here; only per-feature values.