omnixai.explainers.ranking.counterfactual package

mace

The Model-Agnostic Counterfactual Explanation (MACE) for ranking tasks.

omnixai.explainers.ranking.counterfactual.mace module

The Model-Agnostic Counterfactual Explanation (MACE) for ranking tasks.

class omnixai.explainers.ranking.counterfactual.mace.MACEExplainer(training_data, predict_function, ignored_features=None, method='gld', **kwargs)

Bases: ExplainerBase

The Model-Agnostic Counterfactual Explanation (MACE) developed by Yang et al. Please cite the paper MACE: An Efficient Model-Agnostic Framework for Counterfactual Explanation. This version of MACE is designed for ranking tasks only.

Parameters
  • training_data (Optional[Tabular]) – The data used to initialize a MACE explainer. training_data can either be the training dataset for training the machine learning model or None. If training_data is None, it will use the features in the recommended items (test instances) to construct counterfactual explanations. The type of training_data is Tabular (which combines both query and item into one Tabular instance).

  • predict_function (Callable) – The prediction function corresponding to the ranking model to explain. The outputs of the predict_function are the ranking scores.

  • ignored_features (Optional[List]) – The features ignored in generating counterfactual examples.

  • method (str) – The method for generating counterfactual examples, e.g., “gld”, “rl” or “greedy”.

explanation_type = 'local'
alias = ['mace']
explain(X, item_a_index, item_b_index, max_number_examples=5, **kwargs)

Generates counterfactual explanations. It considers two items A and B in the list where A is the baseline example and B is the example to compare. Suppose the ranking scores A > B, it will changes the features in B such that the new example B’ > A, so that the explanations will be ‘if B changes features x, y and z, B will have a high ranking score than A’.

Parameters
  • X (Tabular) – The list of the recommended items given a query. This Tabular instance contains the features of the query and the items.

  • item_a_index (Union[int, List]) – The index of the baseline example (item A).

  • item_b_index (Union[int, List]) – The index of the example to explain (item B).

  • max_number_examples (int) – The maximum number of the generated counterfactual examples.

Return type

CFExplanation

Returns

A CFExplanation object containing the generated explanations.