predict: @param x: a floating point value to predict the label of the prediction function works by recursively calling the predict function of the appropriate subtrees based on the tree's decision boundary
(self, x)
| 138 | return |
| 139 | |
| 140 | def predict(self, x): |
| 141 | """ |
| 142 | predict: |
| 143 | @param x: a floating point value to predict the label of |
| 144 | the prediction function works by recursively calling the predict function |
| 145 | of the appropriate subtrees based on the tree's decision boundary |
| 146 | """ |
| 147 | if self.prediction is not None: |
| 148 | return self.prediction |
| 149 | elif self.left is not None and self.right is not None: |
| 150 | if x >= self.decision_boundary: |
| 151 | return self.right.predict(x) |
| 152 | else: |
| 153 | return self.left.predict(x) |
| 154 | else: |
| 155 | raise ValueError("Decision tree not yet trained") |
| 156 | |
| 157 | |
| 158 | class TestDecisionTree: |
no outgoing calls
no test coverage detected