From 37967bd0cf9bb8b70126d2b9d763869f327021de Mon Sep 17 00:00:00 2001 From: Nathan Berger Date: Mon, 9 Oct 2017 12:42:51 -0500 Subject: [PATCH] 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. --- machine_learning/decision_tree.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/machine_learning/decision_tree.py b/machine_learning/decision_tree.py index dfc2e1676..51f600cac 100644 --- a/machine_learning/decision_tree.py +++ b/machine_learning/decision_tree.py @@ -48,12 +48,15 @@ class Decision_Tree: return if y.ndim != 1: print("Error: Data set labels must be one dimensional") + return if len(X) < 2 * self.min_leaf_size: self.prediction = np.mean(y) + return if self.depth == 1: self.prediction = np.mean(y) + return best_split = 0 min_error = self.mean_squared_error(X,np.mean(y)) * 2