LEWIS

class lingam.LEWIS(epsilon=1e-10, random_state=0)[source]

LEWIS explainer for computing necessity, sufficiency, and necessity-and-sufficiency scores. [1] [2]

References

__init__(epsilon=1e-10, random_state=0)[source]

Initialize LEWIS explainer.

Parameters:
  • epsilon (float, optional (default=1e-10)) – Small constant to avoid division by zero.

  • random_state (int, optional (default=0)) – Random state for reproducibility.

get_scores(df, x_names, x_values, x_prime_values, o_name, k_names=[], k_values=[], c_names=[])[source]

Compute LEWIS explanation scores (Necessity, Sufficiency, and Necessity-and-Sufficiency).

Parameters:
  • df (pandas.DataFrame) – Input data frame.

  • x_names (list of str) – Name of the attribute (or set of attributes) X under causal evaluation.

  • x_values (list) – Target (intervened) value x of X, typically representing an improved or alternative value.

  • x_prime_values (list) – Baseline or contrastive value x’ of X against which x is compared.

  • o_name (str) – Name of the outcome variable produced by the black-box model.

  • k_names (list of str, optional (default=[])) – Names of contextual variables defining the conditioning set K (used for global, local, or contextual explanations).

  • k_values (list, optional (default=[])) – Values corresponding to k_names, forming the concrete context k.

  • c_names (list of str, optional (default=[])) – Names of adjustment variables C satisfying the backdoor criterion.

Returns:

  • necessity (float) – The necessity score.

  • sufficiency (float) – The sufficiency score.

  • necessity_and_sufficiency (float) – The necessity and sufficiency score.