Skip to content

DecisionTree code - suggestion #7

Open
@sabn0

Description

@sabn0

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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions