Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support VFDT trees #9

Open
anjsimmo opened this issue Oct 12, 2023 · 0 comments
Open

Support VFDT trees #9

anjsimmo opened this issue Oct 12, 2023 · 0 comments
Assignees

Comments

@anjsimmo
Copy link
Contributor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants