(mine, gold)
| 37 | |
| 38 | |
| 39 | def 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 | |
| 70 | def test_DecisionTree(N=1): |
nothing calls this directly
no test coverage detected