Skip to content

Support VFDT trees #9

Open
Open
@anjsimmo

Description

@anjsimmo

River_return_condition tests for EFDTNumericBinaryBranch. This needs to be generalised to also support VFDT (HoeffdingTreeClassifier) which uses NumericBinaryBranch (which EFDTNumericBinaryBranch inherits from)

def river_return_condition(node):
    if isinstance(node, river.tree.nodes.efdtc_nodes.EFDTNumericBinaryBranch):
        return Condition(f"attr_{node.feature}", Operator.LE, node.threshold)
    elif isinstance(node, tuple):  # Multinomial
        feature = node[0].feature
        threshold = node[0]._r_mapping[node[1]]
        return Condition(f"attr_{feature}", Operator.EQ, threshold)
    else:
        raise ValueError(node)

This results in the following exception when run on a HoeffdingTreeClassifier rather than a ExtremelyFastDecisionTreeClassifier

Traceback (most recent call last):
  File "/home/anj/src/paper-decision-trees/tree_diff2/experiment2.py", line 260, in eval_efdt
    batch1_rules = Ruleset(river_extract_rules(model_batch._root,river_children, river_is_leaf))
  File "/home/anj/src/paper-decision-trees/tree_diff2/tree_diff/tree_ruleset_conversion.py", line 137, in river_extract_rules
    return [river_create_rule(p) for p in walk_tree(tree, children, is_leaf)]
  File "/home/anj/src/paper-decision-trees/tree_diff2/tree_diff/tree_ruleset_conversion.py", line 137, in <listcomp>
    return [river_create_rule(p) for p in walk_tree(tree, children, is_leaf)]
  File "/home/anj/src/paper-decision-trees/tree_diff2/tree_diff/tree_ruleset_conversion.py", line 133, in river_create_rule
    return Rule(conditions=river_create_conditions(path[0:-1]), label=f"{label}")
  File "/home/anj/src/paper-decision-trees/tree_diff2/tree_diff/tree_ruleset_conversion.py", line 123, in river_create_conditions
    return [river_return_condition(c) for c in path_conds]
  File "/home/anj/src/paper-decision-trees/tree_diff2/tree_diff/tree_ruleset_conversion.py", line 123, in <listcomp>
    return [river_return_condition(c) for c in path_conds]
  File "/home/anj/src/paper-decision-trees/tree_diff2/tree_diff/tree_ruleset_conversion.py", line 119, in river_return_condition
    raise ValueError(node)
ValueError: NumericBinaryBranch

See the following notebook for a demonstration of the issue: https://github.com/a2i2/tree_diff/blob/re-evaluation/notebooks/Similarity%20Score%20Issues%20-%20VFDT.ipynb

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions