lore_sa.rule.Rule

class lore_sa.rule.Rule(premises: list, consequences: Expression, encoder: EncDec)[source]

Decision rule with premises (conditions) and consequences (predictions).

A Rule represents an if-then decision rule extracted from an interpretable model. It consists of: - Premises: A list of Expression objects that form the “if” part (conditions) - Consequences: An Expression representing the “then” part (predicted class)

Rules are the primary output of LORE explanations, describing when and why a black box model makes specific predictions.

premises

List of Expression objects representing the conditions

Type:

list

consequences

Expression representing the predicted outcome

Type:

Expression

encoder

Encoder/decoder for handling feature transformations

Type:

EncDec

Example

>>> # Rule: IF age > 30 AND income <= 50000 THEN class = 0
>>> premises = [
...     Expression('age', operator.gt, 30),
...     Expression('income', operator.le, 50000)
... ]
>>> consequence = Expression('class', operator.eq, 0)
>>> rule = Rule(premises, consequence, encoder)
>>> print(rule)  # Output: { age > 30, income <= 50000 } --> { class = 0 }
__init__(premises: list, consequences: Expression, encoder: EncDec)[source]

Initialize a decision rule.

Parameters:
  • premises (list) – List of Expression objects representing the rule’s conditions. These are combined with AND logic.

  • consequences (Expression) – Expression representing the rule’s prediction/outcome

  • encoder (EncDec) – Encoder/decoder object used to decode categorical features back to their original representation

Note

The encoder is used to decode one-hot encoded categorical features back to their original categorical values, making the rule more interpretable.

Methods

__init__(premises, consequences, encoder)

Initialize a decision rule.

decode_rule(rule)

is_covered(x, feature_names)

to_dict()