Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DecisionTree code - suggestion #7

Open
sabn0 opened this issue Aug 14, 2023 · 0 comments
Open

DecisionTree code - suggestion #7

sabn0 opened this issue Aug 14, 2023 · 0 comments

Comments

@sabn0
Copy link

sabn0 commented Aug 14, 2023

Hi,
In the DecisionTree implementation, line 33 there is a call to the _most_common_label() method.
Line 33 is reached only if the y numpy array has one unique value, so instead of calling most common
you can simply take the value from any index of the array.

Maybe something like:

# check the stopping criteria
if (depth>=self.max_depth or n_labels==1 or n_samples<self.min_samples_split):
    return Node(value=y[0])

instead of :

# check the stopping criteria
if (depth>=self.max_depth or n_labels==1 or n_samples<self.min_samples_split):
    leaf_value = self._most_common_label(y)
    return Node(value=leaf_value)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant