We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
[PYTEST WARNING] Decision tree
### Feature description

@nbrgr @hrishi84 @cclauss Please could you resolve this warning
```
machine_learning/decision_tree.py::machine_learning.decision_tree.DecisionTree.mean_squared_error
  <doctest machine_learning.decision_tree.DecisionTree.mean_squared_error[2]>:1: DeprecationWarning: `np.float` is a deprecated alias for the builtin `float`. To silence this warning, use `float` by itself. Doing this will not modify any behavior and is safe. If you specifically wanted the numpy scalar type, use `np.float64` here.
  Deprecated in NumPy 1.20; for more details and guidance: https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations

machine_learning/decision_tree.py::machine_learning.decision_tree.DecisionTree.mean_squared_error
machine_learning/decision_tree.py::machine_learning.decision_tree.DecisionTree.mean_squared_error
  /home/runner/work/Python/Python/machine_learning/decision_tree.py:148: DeprecationWarning: `np.float` is a deprecated alias for the builtin `float`. To silence this warning, use `float` by itself. Doing this will not modify any behavior and is safe. If you specifically wanted the numpy scalar type, use `np.float64` here.
  Deprecated in NumPy 1.20; for more details and guidance: https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations
    squared_error_sum = np.float(0)

machine_learning/decision_tree.py::machine_learning.decision_tree.DecisionTree.mean_squared_error
machine_learning/decision_tree.py::machine_learning.decision_tree.DecisionTree.mean_squared_error
  /home/runner/work/Python/Python/machine_learning/decision_tree.py:152: DeprecationWarning: `np.float` is a deprecated alias for the builtin `float`. To silence this warning, use `float` by itself. Doing this will not modify any behavior and is safe. If you specifically wanted the numpy scalar type, use `np.float64` here.
  Deprecated in NumPy 1.20; for more details and guidance: https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations
    return np.float(squared_error_sum / labels.size)

machine_learning/decision_tree.py::machine_learning.decision_tree.DecisionTree.mean_squared_error
  <doctest machine_learning.decision_tree.DecisionTree.mean_squared_error[5]>:1: DeprecationWarning: `np.float` is a deprecated alias for the builtin `float`. To silence this warning, use `float` by itself. Doing this will not modify any behavior and is safe. If you specifically wanted the numpy scalar type, use `np.float64` here.
  Deprecated in NumPy 1.20; for more details and guidance: https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations
```

origin: #7211

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `machine_learning/decision_tree.py`
Content:
```
1 """
2 Implementation of a basic regression decision tree.
3 Input data set: The input data set must be 1-dimensional with continuous labels.
4 Output: The decision tree maps a real number input to a real number output.
5 """
6 import numpy as np
7 
8 
9 class DecisionTree:
10     def __init__(self, depth=5, min_leaf_size=5):
11         self.depth = depth
12         self.decision_boundary = 0
13         self.left = None
14         self.right = None
15         self.min_leaf_size = min_leaf_size
16         self.prediction = None
17 
18     def mean_squared_error(self, labels, prediction):
19         """
20         mean_squared_error:
21         @param labels: a one dimensional numpy array
22         @param prediction: a floating point value
23         return value: mean_squared_error calculates the error if prediction is used to
24             estimate the labels
25         >>> tester = DecisionTree()
26         >>> test_labels = np.array([1,2,3,4,5,6,7,8,9,10])
27         >>> test_prediction = np.float(6)
28         >>> tester.mean_squared_error(test_labels, test_prediction) == (
29         ...     TestDecisionTree.helper_mean_squared_error_test(test_labels,
30         ...         test_prediction))
31         True
32         >>> test_labels = np.array([1,2,3])
33         >>> test_prediction = np.float(2)
34         >>> tester.mean_squared_error(test_labels, test_prediction) == (
35         ...     TestDecisionTree.helper_mean_squared_error_test(test_labels,
36         ...         test_prediction))
37         True
38         """
39         if labels.ndim != 1:
40             print("Error: Input labels must be one dimensional")
41 
42         return np.mean((labels - prediction) ** 2)
43 
44     def train(self, x, y):
45         """
46         train:
47         @param x: a one dimensional numpy array
48         @param y: a one dimensional numpy array.
49         The contents of y are the labels for the corresponding X values
50 
51         train does not have a return value
52         """
53 
54         """
55         this section is to check that the inputs conform to our dimensionality
56         constraints
57         """
58         if x.ndim != 1:
59             print("Error: Input data set must be one dimensional")
60             return
61         if len(x) != len(y):
62             print("Error: X and y have different lengths")
63             return
64         if y.ndim != 1:
65             print("Error: Data set labels must be one dimensional")
66             return
67 
68         if len(x) < 2 * self.min_leaf_size:
69             self.prediction = np.mean(y)
70             return
71 
72         if self.depth == 1:
73             self.prediction = np.mean(y)
74             return
75 
76         best_split = 0
77         min_error = self.mean_squared_error(x, np.mean(y)) * 2
78 
79         """
80         loop over all possible splits for the decision tree. find the best split.
81         if no split exists that is less than 2 * error for the entire array
82         then the data set is not split and the average for the entire array is used as
83         the predictor
84         """
85         for i in range(len(x)):
86             if len(x[:i]) < self.min_leaf_size:
87                 continue
88             elif len(x[i:]) < self.min_leaf_size:
89                 continue
90             else:
91                 error_left = self.mean_squared_error(x[:i], np.mean(y[:i]))
92                 error_right = self.mean_squared_error(x[i:], np.mean(y[i:]))
93                 error = error_left + error_right
94                 if error < min_error:
95                     best_split = i
96                     min_error = error
97 
98         if best_split != 0:
99             left_x = x[:best_split]
100             left_y = y[:best_split]
101             right_x = x[best_split:]
102             right_y = y[best_split:]
103 
104             self.decision_boundary = x[best_split]
105             self.left = DecisionTree(
106                 depth=self.depth - 1, min_leaf_size=self.min_leaf_size
107             )
108             self.right = DecisionTree(
109                 depth=self.depth - 1, min_leaf_size=self.min_leaf_size
110             )
111             self.left.train(left_x, left_y)
112             self.right.train(right_x, right_y)
113         else:
114             self.prediction = np.mean(y)
115 
116         return
117 
118     def predict(self, x):
119         """
120         predict:
121         @param x: a floating point value to predict the label of
122         the prediction function works by recursively calling the predict function
123         of the appropriate subtrees based on the tree's decision boundary
124         """
125         if self.prediction is not None:
126             return self.prediction
127         elif self.left or self.right is not None:
128             if x >= self.decision_boundary:
129                 return self.right.predict(x)
130             else:
131                 return self.left.predict(x)
132         else:
133             print("Error: Decision tree not yet trained")
134             return None
135 
136 
137 class TestDecisionTree:
138     """Decision Tres test class"""
139 
140     @staticmethod
141     def helper_mean_squared_error_test(labels, prediction):
142         """
143         helper_mean_squared_error_test:
144         @param labels: a one dimensional numpy array
145         @param prediction: a floating point value
146         return value: helper_mean_squared_error_test calculates the mean squared error
147         """
148         squared_error_sum = np.float(0)
149         for label in labels:
150             squared_error_sum += (label - prediction) ** 2
151 
152         return np.float(squared_error_sum / labels.size)
153 
154 
155 def main():
156     """
157     In this demonstration we're generating a sample data set from the sin function in
158     numpy.  We then train a decision tree on the data set and use the decision tree to
159     predict the label of 10 different test values. Then the mean squared error over
160     this test is displayed.
161     """
162     x = np.arange(-1.0, 1.0, 0.005)
163     y = np.sin(x)
164 
165     tree = DecisionTree(depth=10, min_leaf_size=10)
166     tree.train(x, y)
167 
168     test_cases = (np.random.rand(10) * 2) - 1
169     predictions = np.array([tree.predict(x) for x in test_cases])
170     avg_error = np.mean((predictions - test_cases) ** 2)
171 
172     print("Test values: " + str(test_cases))
173     print("Predictions: " + str(predictions))
174     print("Average error: " + str(avg_error))
175 
176 
177 if __name__ == "__main__":
178     main()
179     import doctest
180 
181     doctest.testmod(name="mean_squarred_error", verbose=True)
182
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/machine_learning/decision_tree.py b/machine_learning/decision_tree.py
--- a/machine_learning/decision_tree.py
+++ b/machine_learning/decision_tree.py
@@ -24,13 +24,13 @@
             estimate the labels
         >>> tester = DecisionTree()
         >>> test_labels = np.array([1,2,3,4,5,6,7,8,9,10])
-        >>> test_prediction = np.float(6)
+        >>> test_prediction = float(6)
         >>> tester.mean_squared_error(test_labels, test_prediction) == (
         ...     TestDecisionTree.helper_mean_squared_error_test(test_labels,
         ...         test_prediction))
         True
         >>> test_labels = np.array([1,2,3])
-        >>> test_prediction = np.float(2)
+        >>> test_prediction = float(2)
         >>> tester.mean_squared_error(test_labels, test_prediction) == (
         ...     TestDecisionTree.helper_mean_squared_error_test(test_labels,
         ...         test_prediction))
@@ -145,11 +145,11 @@
         @param prediction: a floating point value
         return value: helper_mean_squared_error_test calculates the mean squared error
         """
-        squared_error_sum = np.float(0)
+        squared_error_sum = float(0)
         for label in labels:
             squared_error_sum += (label - prediction) ** 2
 
-        return np.float(squared_error_sum / labels.size)
+        return float(squared_error_sum / labels.size)
 
 
 def main():

{"golden_diff": "diff --git a/machine_learning/decision_tree.py b/machine_learning/decision_tree.py\n--- a/machine_learning/decision_tree.py\n+++ b/machine_learning/decision_tree.py\n@@ -24,13 +24,13 @@\n             estimate the labels\n         >>> tester = DecisionTree()\n         >>> test_labels = np.array([1,2,3,4,5,6,7,8,9,10])\n-        >>> test_prediction = np.float(6)\n+        >>> test_prediction = float(6)\n         >>> tester.mean_squared_error(test_labels, test_prediction) == (\n         ...     TestDecisionTree.helper_mean_squared_error_test(test_labels,\n         ...         test_prediction))\n         True\n         >>> test_labels = np.array([1,2,3])\n-        >>> test_prediction = np.float(2)\n+        >>> test_prediction = float(2)\n         >>> tester.mean_squared_error(test_labels, test_prediction) == (\n         ...     TestDecisionTree.helper_mean_squared_error_test(test_labels,\n         ...         test_prediction))\n@@ -145,11 +145,11 @@\n         @param prediction: a floating point value\n         return value: helper_mean_squared_error_test calculates the mean squared error\n         \"\"\"\n-        squared_error_sum = np.float(0)\n+        squared_error_sum = float(0)\n         for label in labels:\n             squared_error_sum += (label - prediction) ** 2\n \n-        return np.float(squared_error_sum / labels.size)\n+        return float(squared_error_sum / labels.size)\n \n \n def main():\n", "issue": "[PYTEST WARNING] Decision tree\n### Feature description\n\n@nbrgr @hrishi84 @cclauss Please could you resolve this warning\r\n```\r\nmachine_learning/decision_tree.py::machine_learning.decision_tree.DecisionTree.mean_squared_error\r\n  <doctest machine_learning.decision_tree.DecisionTree.mean_squared_error[2]>:1: DeprecationWarning: `np.float` is a deprecated alias for the builtin `float`. To silence this warning, use `float` by itself. Doing this will not modify any behavior and is safe. If you specifically wanted the numpy scalar type, use `np.float64` here.\r\n  Deprecated in NumPy 1.20; for more details and guidance: https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations\r\n\r\nmachine_learning/decision_tree.py::machine_learning.decision_tree.DecisionTree.mean_squared_error\r\nmachine_learning/decision_tree.py::machine_learning.decision_tree.DecisionTree.mean_squared_error\r\n  /home/runner/work/Python/Python/machine_learning/decision_tree.py:148: DeprecationWarning: `np.float` is a deprecated alias for the builtin `float`. To silence this warning, use `float` by itself. Doing this will not modify any behavior and is safe. If you specifically wanted the numpy scalar type, use `np.float64` here.\r\n  Deprecated in NumPy 1.20; for more details and guidance: https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations\r\n    squared_error_sum = np.float(0)\r\n\r\nmachine_learning/decision_tree.py::machine_learning.decision_tree.DecisionTree.mean_squared_error\r\nmachine_learning/decision_tree.py::machine_learning.decision_tree.DecisionTree.mean_squared_error\r\n  /home/runner/work/Python/Python/machine_learning/decision_tree.py:152: DeprecationWarning: `np.float` is a deprecated alias for the builtin `float`. To silence this warning, use `float` by itself. Doing this will not modify any behavior and is safe. If you specifically wanted the numpy scalar type, use `np.float64` here.\r\n  Deprecated in NumPy 1.20; for more details and guidance: https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations\r\n    return np.float(squared_error_sum / labels.size)\r\n\r\nmachine_learning/decision_tree.py::machine_learning.decision_tree.DecisionTree.mean_squared_error\r\n  <doctest machine_learning.decision_tree.DecisionTree.mean_squared_error[5]>:1: DeprecationWarning: `np.float` is a deprecated alias for the builtin `float`. To silence this warning, use `float` by itself. Doing this will not modify any behavior and is safe. If you specifically wanted the numpy scalar type, use `np.float64` here.\r\n  Deprecated in NumPy 1.20; for more details and guidance: https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations\r\n```\r\n\r\norigin: #7211\n", "before_files": [{"content": "\"\"\"\nImplementation of a basic regression decision tree.\nInput data set: The input data set must be 1-dimensional with continuous labels.\nOutput: The decision tree maps a real number input to a real number output.\n\"\"\"\nimport numpy as np\n\n\nclass DecisionTree:\n    def __init__(self, depth=5, min_leaf_size=5):\n        self.depth = depth\n        self.decision_boundary = 0\n        self.left = None\n        self.right = None\n        self.min_leaf_size = min_leaf_size\n        self.prediction = None\n\n    def mean_squared_error(self, labels, prediction):\n        \"\"\"\n        mean_squared_error:\n        @param labels: a one dimensional numpy array\n        @param prediction: a floating point value\n        return value: mean_squared_error calculates the error if prediction is used to\n            estimate the labels\n        >>> tester = DecisionTree()\n        >>> test_labels = np.array([1,2,3,4,5,6,7,8,9,10])\n        >>> test_prediction = np.float(6)\n        >>> tester.mean_squared_error(test_labels, test_prediction) == (\n        ...     TestDecisionTree.helper_mean_squared_error_test(test_labels,\n        ...         test_prediction))\n        True\n        >>> test_labels = np.array([1,2,3])\n        >>> test_prediction = np.float(2)\n        >>> tester.mean_squared_error(test_labels, test_prediction) == (\n        ...     TestDecisionTree.helper_mean_squared_error_test(test_labels,\n        ...         test_prediction))\n        True\n        \"\"\"\n        if labels.ndim != 1:\n            print(\"Error: Input labels must be one dimensional\")\n\n        return np.mean((labels - prediction) ** 2)\n\n    def train(self, x, y):\n        \"\"\"\n        train:\n        @param x: a one dimensional numpy array\n        @param y: a one dimensional numpy array.\n        The contents of y are the labels for the corresponding X values\n\n        train does not have a return value\n        \"\"\"\n\n        \"\"\"\n        this section is to check that the inputs conform to our dimensionality\n        constraints\n        \"\"\"\n        if x.ndim != 1:\n            print(\"Error: Input data set must be one dimensional\")\n            return\n        if len(x) != len(y):\n            print(\"Error: X and y have different lengths\")\n            return\n        if y.ndim != 1:\n            print(\"Error: Data set labels must be one dimensional\")\n            return\n\n        if len(x) < 2 * self.min_leaf_size:\n            self.prediction = np.mean(y)\n            return\n\n        if self.depth == 1:\n            self.prediction = np.mean(y)\n            return\n\n        best_split = 0\n        min_error = self.mean_squared_error(x, np.mean(y)) * 2\n\n        \"\"\"\n        loop over all possible splits for the decision tree. find the best split.\n        if no split exists that is less than 2 * error for the entire array\n        then the data set is not split and the average for the entire array is used as\n        the predictor\n        \"\"\"\n        for i in range(len(x)):\n            if len(x[:i]) < self.min_leaf_size:\n                continue\n            elif len(x[i:]) < self.min_leaf_size:\n                continue\n            else:\n                error_left = self.mean_squared_error(x[:i], np.mean(y[:i]))\n                error_right = self.mean_squared_error(x[i:], np.mean(y[i:]))\n                error = error_left + error_right\n                if error < min_error:\n                    best_split = i\n                    min_error = error\n\n        if best_split != 0:\n            left_x = x[:best_split]\n            left_y = y[:best_split]\n            right_x = x[best_split:]\n            right_y = y[best_split:]\n\n            self.decision_boundary = x[best_split]\n            self.left = DecisionTree(\n                depth=self.depth - 1, min_leaf_size=self.min_leaf_size\n            )\n            self.right = DecisionTree(\n                depth=self.depth - 1, min_leaf_size=self.min_leaf_size\n            )\n            self.left.train(left_x, left_y)\n            self.right.train(right_x, right_y)\n        else:\n            self.prediction = np.mean(y)\n\n        return\n\n    def predict(self, x):\n        \"\"\"\n        predict:\n        @param x: a floating point value to predict the label of\n        the prediction function works by recursively calling the predict function\n        of the appropriate subtrees based on the tree's decision boundary\n        \"\"\"\n        if self.prediction is not None:\n            return self.prediction\n        elif self.left or self.right is not None:\n            if x >= self.decision_boundary:\n                return self.right.predict(x)\n            else:\n                return self.left.predict(x)\n        else:\n            print(\"Error: Decision tree not yet trained\")\n            return None\n\n\nclass TestDecisionTree:\n    \"\"\"Decision Tres test class\"\"\"\n\n    @staticmethod\n    def helper_mean_squared_error_test(labels, prediction):\n        \"\"\"\n        helper_mean_squared_error_test:\n        @param labels: a one dimensional numpy array\n        @param prediction: a floating point value\n        return value: helper_mean_squared_error_test calculates the mean squared error\n        \"\"\"\n        squared_error_sum = np.float(0)\n        for label in labels:\n            squared_error_sum += (label - prediction) ** 2\n\n        return np.float(squared_error_sum / labels.size)\n\n\ndef main():\n    \"\"\"\n    In this demonstration we're generating a sample data set from the sin function in\n    numpy.  We then train a decision tree on the data set and use the decision tree to\n    predict the label of 10 different test values. Then the mean squared error over\n    this test is displayed.\n    \"\"\"\n    x = np.arange(-1.0, 1.0, 0.005)\n    y = np.sin(x)\n\n    tree = DecisionTree(depth=10, min_leaf_size=10)\n    tree.train(x, y)\n\n    test_cases = (np.random.rand(10) * 2) - 1\n    predictions = np.array([tree.predict(x) for x in test_cases])\n    avg_error = np.mean((predictions - test_cases) ** 2)\n\n    print(\"Test values: \" + str(test_cases))\n    print(\"Predictions: \" + str(predictions))\n    print(\"Average error: \" + str(avg_error))\n\n\nif __name__ == \"__main__\":\n    main()\n    import doctest\n\n    doctest.testmod(name=\"mean_squarred_error\", verbose=True)\n", "path": "machine_learning/decision_tree.py"}], "after_files": [{"content": "\"\"\"\nImplementation of a basic regression decision tree.\nInput data set: The input data set must be 1-dimensional with continuous labels.\nOutput: The decision tree maps a real number input to a real number output.\n\"\"\"\nimport numpy as np\n\n\nclass DecisionTree:\n    def __init__(self, depth=5, min_leaf_size=5):\n        self.depth = depth\n        self.decision_boundary = 0\n        self.left = None\n        self.right = None\n        self.min_leaf_size = min_leaf_size\n        self.prediction = None\n\n    def mean_squared_error(self, labels, prediction):\n        \"\"\"\n        mean_squared_error:\n        @param labels: a one dimensional numpy array\n        @param prediction: a floating point value\n        return value: mean_squared_error calculates the error if prediction is used to\n            estimate the labels\n        >>> tester = DecisionTree()\n        >>> test_labels = np.array([1,2,3,4,5,6,7,8,9,10])\n        >>> test_prediction = float(6)\n        >>> tester.mean_squared_error(test_labels, test_prediction) == (\n        ...     TestDecisionTree.helper_mean_squared_error_test(test_labels,\n        ...         test_prediction))\n        True\n        >>> test_labels = np.array([1,2,3])\n        >>> test_prediction = float(2)\n        >>> tester.mean_squared_error(test_labels, test_prediction) == (\n        ...     TestDecisionTree.helper_mean_squared_error_test(test_labels,\n        ...         test_prediction))\n        True\n        \"\"\"\n        if labels.ndim != 1:\n            print(\"Error: Input labels must be one dimensional\")\n\n        return np.mean((labels - prediction) ** 2)\n\n    def train(self, x, y):\n        \"\"\"\n        train:\n        @param x: a one dimensional numpy array\n        @param y: a one dimensional numpy array.\n        The contents of y are the labels for the corresponding X values\n\n        train does not have a return value\n        \"\"\"\n\n        \"\"\"\n        this section is to check that the inputs conform to our dimensionality\n        constraints\n        \"\"\"\n        if x.ndim != 1:\n            print(\"Error: Input data set must be one dimensional\")\n            return\n        if len(x) != len(y):\n            print(\"Error: X and y have different lengths\")\n            return\n        if y.ndim != 1:\n            print(\"Error: Data set labels must be one dimensional\")\n            return\n\n        if len(x) < 2 * self.min_leaf_size:\n            self.prediction = np.mean(y)\n            return\n\n        if self.depth == 1:\n            self.prediction = np.mean(y)\n            return\n\n        best_split = 0\n        min_error = self.mean_squared_error(x, np.mean(y)) * 2\n\n        \"\"\"\n        loop over all possible splits for the decision tree. find the best split.\n        if no split exists that is less than 2 * error for the entire array\n        then the data set is not split and the average for the entire array is used as\n        the predictor\n        \"\"\"\n        for i in range(len(x)):\n            if len(x[:i]) < self.min_leaf_size:\n                continue\n            elif len(x[i:]) < self.min_leaf_size:\n                continue\n            else:\n                error_left = self.mean_squared_error(x[:i], np.mean(y[:i]))\n                error_right = self.mean_squared_error(x[i:], np.mean(y[i:]))\n                error = error_left + error_right\n                if error < min_error:\n                    best_split = i\n                    min_error = error\n\n        if best_split != 0:\n            left_x = x[:best_split]\n            left_y = y[:best_split]\n            right_x = x[best_split:]\n            right_y = y[best_split:]\n\n            self.decision_boundary = x[best_split]\n            self.left = DecisionTree(\n                depth=self.depth - 1, min_leaf_size=self.min_leaf_size\n            )\n            self.right = DecisionTree(\n                depth=self.depth - 1, min_leaf_size=self.min_leaf_size\n            )\n            self.left.train(left_x, left_y)\n            self.right.train(right_x, right_y)\n        else:\n            self.prediction = np.mean(y)\n\n        return\n\n    def predict(self, x):\n        \"\"\"\n        predict:\n        @param x: a floating point value to predict the label of\n        the prediction function works by recursively calling the predict function\n        of the appropriate subtrees based on the tree's decision boundary\n        \"\"\"\n        if self.prediction is not None:\n            return self.prediction\n        elif self.left or self.right is not None:\n            if x >= self.decision_boundary:\n                return self.right.predict(x)\n            else:\n                return self.left.predict(x)\n        else:\n            print(\"Error: Decision tree not yet trained\")\n            return None\n\n\nclass TestDecisionTree:\n    \"\"\"Decision Tres test class\"\"\"\n\n    @staticmethod\n    def helper_mean_squared_error_test(labels, prediction):\n        \"\"\"\n        helper_mean_squared_error_test:\n        @param labels: a one dimensional numpy array\n        @param prediction: a floating point value\n        return value: helper_mean_squared_error_test calculates the mean squared error\n        \"\"\"\n        squared_error_sum = float(0)\n        for label in labels:\n            squared_error_sum += (label - prediction) ** 2\n\n        return float(squared_error_sum / labels.size)\n\n\ndef main():\n    \"\"\"\n    In this demonstration we're generating a sample data set from the sin function in\n    numpy.  We then train a decision tree on the data set and use the decision tree to\n    predict the label of 10 different test values. Then the mean squared error over\n    this test is displayed.\n    \"\"\"\n    x = np.arange(-1.0, 1.0, 0.005)\n    y = np.sin(x)\n\n    tree = DecisionTree(depth=10, min_leaf_size=10)\n    tree.train(x, y)\n\n    test_cases = (np.random.rand(10) * 2) - 1\n    predictions = np.array([tree.predict(x) for x in test_cases])\n    avg_error = np.mean((predictions - test_cases) ** 2)\n\n    print(\"Test values: \" + str(test_cases))\n    print(\"Predictions: \" + str(predictions))\n    print(\"Average error: \" + str(avg_error))\n\n\nif __name__ == \"__main__\":\n    main()\n    import doctest\n\n    doctest.testmod(name=\"mean_squarred_error\", verbose=True)\n", "path": "machine_learning/decision_tree.py"}]}