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)
| 98 | return |
| 99 | |
| 100 | def predict(self, x): |
| 101 | """ |
| 102 | predict: |
| 103 | @param x: a floating point value to predict the label of |
| 104 | the prediction function works by recursively calling the predict function |
| 105 | of the appropriate subtrees based on the tree's decision boundary |
| 106 | """ |
| 107 | if self.prediction is not None: |
| 108 | return self.prediction |
| 109 | elif self.left or self.right is not None: |
| 110 | if x >= self.decision_boundary: |
| 111 | return self.right.predict(x) |
| 112 | else: |
| 113 | return self.left.predict(x) |
| 114 | else: |
| 115 | print("Error: Decision tree not yet trained") |
| 116 | return None |
| 117 | |
| 118 | def main(): |
| 119 | """ |
no outgoing calls
no test coverage detected