MCPcopy Create free account
hub / github.com/ddbourgin/numpy-ml / compare_trees

Function compare_trees

numpy_ml/tests/test_trees.py:39–67  ·  view source on GitHub ↗
(mine, gold)

Source from the content-addressed store, hash-verified

37
38
39def compare_trees(mine, gold):
40 clone = clone_tree(gold)
41 mine = mine.root
42
43 def test(mine, clone):
44 if isinstance(clone, Node) and isinstance(mine, Node):
45 assert mine.feature == clone.feature, "Node {} not equal".format(depth)
46 np.testing.assert_allclose(mine.threshold, clone.threshold)
47 test(mine.left, clone.left, depth + 1)
48 test(mine.right, clone.right, depth + 1)
49 elif isinstance(clone, Leaf) and isinstance(mine, Leaf):
50 np.testing.assert_allclose(mine.value, clone.value)
51 return
52 else:
53 raise ValueError("Nodes at depth {} are not equal".format(depth))
54
55 depth = 0
56 ok = True
57 while ok:
58 if isinstance(clone, Node) and isinstance(mine, Node):
59 assert mine.feature == clone.feature
60 np.testing.assert_allclose(mine.threshold, clone.threshold)
61 test(mine.left, clone.left, depth + 1)
62 test(mine.right, clone.right, depth + 1)
63 elif isinstance(clone, Leaf) and isinstance(mine, Leaf):
64 np.testing.assert_allclose(mine.value, clone.value)
65 return
66 else:
67 raise ValueError("Nodes at depth {} are not equal".format(depth))
68
69
70def test_DecisionTree(N=1):

Callers

nothing calls this directly

Calls 2

clone_treeFunction · 0.85
testFunction · 0.85

Tested by

no test coverage detected