Skip to content

Commit 37967bd

Browse files
committed
Fixed case where function didn't return where it should
I added these return statements so that invalid inputs or valid end cases would no longer continue running through the rest of the function.
1 parent 8fb1eb7 commit 37967bd

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

machine_learning/decision_tree.py

+3
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,15 @@ def train(self, X, y):
4848
return
4949
if y.ndim != 1:
5050
print("Error: Data set labels must be one dimensional")
51+
return
5152

5253
if len(X) < 2 * self.min_leaf_size:
5354
self.prediction = np.mean(y)
55+
return
5456

5557
if self.depth == 1:
5658
self.prediction = np.mean(y)
59+
return
5760

5861
best_split = 0
5962
min_error = self.mean_squared_error(X,np.mean(y)) * 2

0 commit comments

Comments
 (0)