mirror of
https://github.com/TheAlgorithms/Python.git
synced 2024-11-27 23:11:09 +00:00
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:
parent
8fb1eb7bdf
commit
37967bd0cf
|
@ -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
|
||||||
|
|
Loading…
Reference in New Issue
Block a user