Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Update logical issue in decision_tree.py (TheAlgorithms#13303)
Co-authored-by: Maxim Smolskiy <mithridatus@mail.ru>
  • Loading branch information
HarshPathak310 and MaximSmolskiy authored Oct 17, 2025
commit c79034ca2114e56ede887a473c2853b8c6d49257
7 changes: 3 additions & 4 deletions machine_learning/decision_tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,14 +146,13 @@ def predict(self, x):
"""
if self.prediction is not None:
return self.prediction
elif self.left or self.right is not None:
elif self.left is not None and self.right is not None:
if x >= self.decision_boundary:
return self.right.predict(x)
else:
return self.left.predict(x)
else:
print("Error: Decision tree not yet trained")
return None
raise ValueError("Decision tree not yet trained")


class TestDecisionTree:
Expand Down Expand Up @@ -201,4 +200,4 @@ def main():
main()
import doctest

doctest.testmod(name="mean_squarred_error", verbose=True)
doctest.testmod(name="mean_squared_error", verbose=True)