xai_compare.explainers.permutation_wrapper

Classes

Permutations(model, X_train, y_train[, ...])

A class that encapsulates the Permutation Feature Importance method for explaining model predictions.

class xai_compare.explainers.permutation_wrapper.Permutations(model, X_train: DataFrame, y_train: DataFrame | Series | ndarray, mode: str = 'regression', num_permutations: int = 5, random_state: int | None = None)

A class that encapsulates the Permutation Feature Importance method for explaining model predictions. Further details can be found in the literature, such as in the book “Interpretable Machine Learning” by Christoph Molnar, which discusses various interpretation methods including permutation importance. (https://christophm.github.io/interpretable-ml-book/feature-importance.html)

Attributes:
model:

An input machine learning model.

X_train (pd.DataFrame):

Training data features.

y_train (Union[pd.DataFrame, pd.Series, np.ndarray]):

Training data labels.

mode (str):

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

num_permutations (int):

Number of permutations to perform for each feature.

random_state (Union[int, None]):

Seed for the random number generator.

explain_global(X_data: DataFrame) DataFrame

Calculates permutation feature importance for a given model.

Attributes:
X_data (pd.DataFrame):

The feature matrix for which permutation importance is calculated.

Returns:
pd.DataFrame:

A DataFrame containing the feature names and their mean importance.

explain_local(X_data: DataFrame) DataFrame

This function is not applicable for permutation feature importance as it is a global method.

Attributes:

Not applicable.

Returns:
None:

This function does not return any value.