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.
This commit is contained in:
Nathan Berger 2017-10-09 12:42:51 -05:00
parent 8fb1eb7bdf
commit 37967bd0cf

View File

@ -48,12 +48,15 @@ class Decision_Tree:
return return
if y.ndim != 1: if y.ndim != 1:
print("Error: Data set labels must be one dimensional") print("Error: Data set labels must be one dimensional")
return
if len(X) < 2 * self.min_leaf_size: if len(X) < 2 * self.min_leaf_size:
self.prediction = np.mean(y) self.prediction = np.mean(y)
return
if self.depth == 1: if self.depth == 1:
self.prediction = np.mean(y) self.prediction = np.mean(y)
return
best_split = 0 best_split = 0
min_error = self.mean_squared_error(X,np.mean(y)) * 2 min_error = self.mean_squared_error(X,np.mean(y)) * 2