From 8a705193ea4a58576de8cb66f7abb6e09724b679 Mon Sep 17 00:00:00 2001 From: Suyash Dongre <109069262+Suyashd999@users.noreply.github.com> Date: Fri, 3 Nov 2023 23:32:16 +0530 Subject: [PATCH] Added doctest to decision_tree.py --- machine_learning/decision_tree.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/machine_learning/decision_tree.py b/machine_learning/decision_tree.py index 7cd1b02c4181..8ec17d1cd4e4 100644 --- a/machine_learning/decision_tree.py +++ b/machine_learning/decision_tree.py @@ -49,6 +49,26 @@ def train(self, x, y): The contents of y are the labels for the corresponding X values train does not have a return value + + Examples: + 1. Try to train when x & y are of same length & 1 dimesions (No errors) + >>> dt = DecisionTree() + >>> dt.train(np.array([10,20,30,40,50]),np.array([0,0,0,1,1])) + + 2. Try to train when x is 2 dimesions + >>> dt = DecisionTree() + >>> dt.train(np.array([[1,2,3,4,5],[1,2,3,4,5]]),np.array([0,0,0,1,1])) + Error: Input data set must be one dimensional + + 3. Try to train when x and y are not of same length + >>> dt = DecisionTree() + >>> dt.train(np.array([1,2,3,4,5]),np.array([[0,0,0,1,1],[0,0,0,1,1]])) + Error: X and y have different lengths + + 4. Try to train when x & y are of same length but diffetent dimesions + >>> dt = DecisionTree() + >>> dt.train(np.array([1,2,3,4,5]),np.array([[1],[2],[3],[4],[5]])) + Error: Data set labels must be one dimensional """ """