shapiq.imputer.GenerativeConditionalImputer¶

class shapiq.imputer.GenerativeConditionalImputer(model, data, x=None, *, sample_size=10, conditional_budget=128, conditional_threshold=0.05, normalize=True, categorical_features=None, method='generative', random_state=None)[source]¶

Bases: Imputer

A GenerativeConditionalImputer for the shapiq package.

The GenerativeConditionalImputer is used to impute the missing values of a data point by using the conditional distribution estimated with the background data.

Variables:

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

Parameters:
  • model (TModel)

  • data (ndarray)

  • x (np.ndarray | None)

  • sample_size (int)

  • conditional_budget (int)

  • conditional_threshold (float)

  • normalize (bool)

  • categorical_features (list[int] | None)

  • method (Literal['generative'])

  • random_state (int | None)

Initializes the GenerativeConditionalImputer.

Parameters:
  • model (Any) – 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 two-dimensional array with shape (n_samples, n_features).

  • x (ndarray | None) – The explanation point to use the imputer on.

  • sample_size (int) – The number of samples to draw from the conditional background data for imputation. Defaults to 10.

  • conditional_budget (int) – The number of coallitions to sample per each point in data for training the generative model. Defaults to 16.

  • conditional_threshold (float) – A quantile threshold defining a neighbourhood of samples to draw sample_size from. A value between 0.0 and 1.0. Defaults to 0.05.

  • normalize (bool) – A flag to normalize the game values. If True (default), then the game values are normalized and centered to be zero for the empty set of features. Defaults to True.

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

  • method (Literal['generative']) – The method to use for the GenerativeConditionalImputer. Currently only "generative" is implemented. Defaults to "generative".

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

calc_empty_prediction()[source]¶

Runs the model on empty data points (all features missing) to get the empty prediction.

Return type:

float

Returns:

The empty prediction.

init_background(data)[source]¶

Initializes the GenerativeConditionalImputer.

Parameters:

data (ndarray) – The background data to use for the imputer. The shape of the array must be (n_samples, n_features).

Return type:

GenerativeConditionalImputer

Returns:

The initialized imputer.

value_function(coalitions)[source]¶

Computes the value function for all coalitions.

Parameters:

coalitions (ndarray) – A boolean array indicating which features are present (True) and which are missing (False). The shape of the array must be (n_subsets, n_features).

Return type:

ndarray

Returns:

The model’s predictions on the imputed data points. The shape of the array is

(n_subsets, n_outputs).