mean_squared_error: @param labels: a one-dimensional numpy array @param prediction: a floating point value return value: mean_squared_error calculates the error if prediction is used to estimate the labels >>> tester = DecisionTree() >>> t
(self, labels, prediction)
| 17 | self.prediction = None |
| 18 | |
| 19 | def mean_squared_error(self, labels, prediction): |
| 20 | """ |
| 21 | mean_squared_error: |
| 22 | @param labels: a one-dimensional numpy array |
| 23 | @param prediction: a floating point value |
| 24 | return value: mean_squared_error calculates the error if prediction is used to |
| 25 | estimate the labels |
| 26 | >>> tester = DecisionTree() |
| 27 | >>> test_labels = np.array([1,2,3,4,5,6,7,8,9,10]) |
| 28 | >>> test_prediction = float(6) |
| 29 | >>> bool(tester.mean_squared_error(test_labels, test_prediction) == ( |
| 30 | ... TestDecisionTree.helper_mean_squared_error_test(test_labels, |
| 31 | ... test_prediction))) |
| 32 | True |
| 33 | >>> test_labels = np.array([1,2,3]) |
| 34 | >>> test_prediction = float(2) |
| 35 | >>> bool(tester.mean_squared_error(test_labels, test_prediction) == ( |
| 36 | ... TestDecisionTree.helper_mean_squared_error_test(test_labels, |
| 37 | ... test_prediction))) |
| 38 | True |
| 39 | """ |
| 40 | if labels.ndim != 1: |
| 41 | print("Error: Input labels must be one dimensional") |
| 42 | |
| 43 | return np.mean((labels - prediction) ** 2) |
| 44 | |
| 45 | def train(self, x, y): |
| 46 | """ |