jaclearn.logic.decision_tree.rule#
Classes
A decision rule is a pair of (DNF, label). |
|
Functions
|
Extract logic rules (DNF) from a trained DecisionTreeClassifier. |
Class AtomicDecisionRule
- class AtomicDecisionRule[source]#
Bases:
object
- __init__(variable, threshold, right_branch=False)[source]#
Instantiate an atomic decision rule. That is, by comparing a variable with a threshold.
left branch: variable <= threshold
right branch: variable > threshold
- __new__(**kwargs)#
- format(format)[source]#
Format an atomic decision rule into a string.
- Parameters:
format (Union[DecisionRuleFormat, str]) – the format.
Class DecisionRule
- class DecisionRule[source]#
Bases:
object
A decision rule is a pair of (DNF, label).
- __init__(clauses, label, probabilities=None)[source]#
Instantiate a decision formula.
- Parameters:
clauses (Sequence[Sequence[AtomicDecisionRule]]) – the DNF, represented as a two-level nested list.
label (Any) – the output label.
- __new__(**kwargs)#
- format_clause(format)[source]#
- Parameters:
format (DecisionRuleFormat | str)
Class DecisionRuleFormat
- class DecisionRuleFormat[source]#
Bases:
JacEnum
- __new__(value)#
- classmethod assert_valid(value)#
Assert if the value is a valid choice.
- classmethod choice_names()#
Returns the list of the name of all possible choices.
- classmethod choice_objs()#
Returns the list of the object of all possible choices.
- classmethod choice_values()#
Returns the list of the value of all possible choices.
- classmethod is_valid(value)#
Check if the value is a valid choice.
- classmethod type_name()#
Return the type name of the enum.
- LISP = 'lisp'#
- PYTHON = 'python'#
Functions
- extract_rule(decision_tree, feature_names, boolean_input=True, boolean_output=False, multi_output=False)[source]#
Extract logic rules (DNF) from a trained DecisionTreeClassifier.
- Parameters:
decision_tree (DecisionTreeClassifier) – a pre-trained decision tree.
feature_names (Sequence[str]) – a list of strings for the features.
boolean_input (Optional[bool]) – whether the input features are boolean or not.
boolean_output (Optional[bool]) – whether the output features are boolean or not.
multi_output (bool) – whether the output features are multi-valued or not. In this case, all possible values at a leaf node will be registered.
- Returns:
A mapping from label (strings, integers…) to the corresponding rule.
- Return type:
rule_dict (Mapping[Any, DecisionRule])