xai_compare.explainers.shap_wrapper

Classes

SHAP(model, X_train, y_train[, y_pred, mode])

A class that encapsulates the SHAP (SHapley Additive exPlanations) method for explaining model predictions.

class xai_compare.explainers.shap_wrapper.SHAP(model, X_train: DataFrame, y_train: DataFrame | Series | ndarray, y_pred: DataFrame | Series | ndarray | None = None, mode: str = 'regression')

A class that encapsulates the SHAP (SHapley Additive exPlanations) method for explaining model predictions. The method is detailed in the paper “A Unified Approach to Interpreting Model Predictions” (https://arxiv.org/pdf/1705.07874).

Attributes:
model:

An input machine learning model.

mode (str):

Indicates whether the explainer is used for ‘regression’ or ‘classification’.

choose_explainer(model_type: str) Explainer

Selects an appropriate SHAP explainer based on the model type.

Attributes:
model_type (str):

A string describing the type of the model.

Returns:
sh.Explainer:

A SHAP Explainer class or None if no appropriate explainer is found.

explain_global(x_data: DataFrame) DataFrame

Generates global SHAP values (average) for the features in the dataset.

Attributes:
x_data (pd.DataFrame):

DataFrame containing the feature data.

Returns:
pd.DataFrame:

DataFrame of average SHAP values for each feature.

explain_local(x_data: DataFrame) DataFrame

Generates local SHAP values for the given data points.

Attributes:
x_data (pd.DataFrame):

DataFrame containing the feature data.

Returns:
pd.DataFrame:

DataFrame of SHAP values for each feature and data point.