shapiq.explainer.AgnosticExplainer¶
- class shapiq.explainer.AgnosticExplainer(game, *, n_players=None, index='SV', max_order=1, approximator='auto', random_state=None)[source]¶
Bases:
ExplainerAgnostic Explainer for shapiq.
This explainer is used to explain models that do not have a specific implementation in shapiq. It uses the game-based approach to explain the model’s predictions.
Initialize the AgnosticExplainer.
- Parameters:
game (
Game|Callable[[ndarray],ndarray]) – The cooperative game to be explained. This can be an instance ofshapiq.games.base.Gameor a callable value function that expects a one-hot matrix of coalitions as input and returns the value of the coalition.n_players (
int|None) – The number of players in the game. If not provided, it will be inferred from theshapiq.games.base.Game.index (
Literal['SV','SII','k-SII','STII','FSII','BV','BII','FBII']) – The type of game-theoretic index to be used for the explanation. Defaults to"SV".max_order (
int) – The maximum order of interactions to be computed. Set to1for no interactions (i.e, for Shapley values"SV"or Banzhaf values"BV").approximator (
Union[Approximator[Literal['SV','SII','k-SII','STII','FSII','BV','BII','FBII']],Literal['auto'],Literal['spex','montecarlo','svarm','permutation','regression']]) – The approximator to use for the game-based approach. Defaults to “auto”, which will automatically select the appropriate approximator based on the index and max_order. Other options include “regression”, “spex”, “svarm”, “montecarlo”, and “permutation”. Can also be an instance ofshapiq.approximator._base.Approximator.random_state (
int|None) – The random state to use for reproducibility. Defaults to None.
- Raises:
ValueError – If the game is not an instance of shapiq.games.base.Game and n_players is not specified.
- explain_function(budget, *, x=None, random_state=None, **kwargs)[source]¶
Explain the function using the game-based approach.
- Parameters:
budget (
int) – The budget used for the approximation / computation of interaction values.x (
ndarray|None) – An optional data point to explain. This is only usable if the game is aImputer. If provided, the imputer will be fitted to this data point before computing the interaction values. Defaults toNone.random_state (
int|None) – An optional random state for reproducibility. Defaults toNone. IfNone, no random state is set for the game or approximator.**kwargs (
Any) – Additional keyword arguments (not used, only for compatibility).
- Returns:
The computed interaction values.
- Return type: