shapiq.imputer.Imputer¶

class shapiq.imputer.Imputer(model, data, x=None, *, sample_size=100, categorical_features=None, random_state=None, verbose=False)[source]¶

Bases: Game, Generic[TModel]

Base class for Imputers.

Initializes the base imputer.

Parameters:
  • model (TypeVar(TModel)) – The model to explain as a callable function expecting a data points as input and returning the model’s predictions.

  • data (ndarray) – The background data to use for the explainer as a 2-dimensional array with shape (n_samples, n_features).

  • x (ndarray | None) – The explanation point to use the imputer on either as a 2-dimensional array with shape (1, n_features) or as a vector with shape (n_features,).

  • sample_size (int | None) – The number of samples to draw from the background data. Defaults to 100 but is usually overwritten in the subclasses.

  • categorical_features (list[int] | None) – A list of indices of the categorical features in the background data.

  • random_state (int | None) – The random state to use for sampling. Defaults to None.

  • verbose (bool) – A flag to enable verbose imputation, which will print a progress bar for model evaluation. Note that this can slow down the imputation process. Defaults to False.

fit(x)[source]¶

Fits the imputer to the explanation point.

Parameters:

x (ndarray) – The explanation point to use the imputer on either as a 2-dimensional array with shape (1, n_features) or as a vector with shape (n_features,).

Return type:

Imputer

Returns:

The fitted imputer.

insert_empty_value(outputs, coalitions)[source]¶

Inserts the empty value into the outputs.

Parameters:
  • outputs (ndarray) – The model’s predictions on the imputed data points.

  • coalitions (ndarray) – The coalitions for which the model’s predictions were made.

Return type:

ndarray

Returns:

The model’s predictions with the empty value inserted for the empty coalitions.

predict(x)[source]¶

Provides a unified prediction interface.

Parameters:

x (ndarray) – The data point to predict the model’s output for.

Return type:

ndarray

Returns:

The model’s prediction for the given data point as a vector.

set_random_state(random_state=None)[source]¶

Sets the random state for the imputer and the model.

Parameters:

random_state (int | None) – The random state to set. Defaults to None, which will set a not deterministic random state.

Return type:

None

data: ndarray¶

The background data to use for the imputer.

empty_prediction: float¶

The model’s prediction on an empty data point (all features missing).

model: TModel¶

The model to impute missing values for.

n_features: int¶

The number of features in the data (equals the number of players in the game).

random_state: int | None¶

The random state to use for sampling.

property sample_size: int¶

Returns the sample size.

property x: ndarray¶

Returns the explanation point if it is set.