Skip to content

Commit

Permalink
fix: leaf node return edge length 0
Browse files Browse the repository at this point in the history
  • Loading branch information
shenxiangzhuang committed Oct 27, 2024
1 parent 43f9dbb commit 10cc6f2
Showing 1 changed file with 1 addition and 4 deletions.
5 changes: 1 addition & 4 deletions toyml/ensemble/iforest.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,8 @@ def fit(self, samples: list[list[float]]) -> IsolationTree:
def get_sample_path_length(self, sample: list[float]) -> float:
if self.is_external_node():
assert self.sample_size_ is not None
# sklearn: https://github.com/scikit-learn/scikit-learn/blob/6e9039160f0dfc3153643143af4cfdca941d2045/sklearn/ensemble/_iforest.py#L517-L518
# For a single training sample, denominator and depth are 0.
# Therefore, we set the score manually to 1.
if self.sample_size_ == 1:
return 1
return 0
else:
return bst_expect_length(self.sample_size_)

Expand Down

0 comments on commit 10cc6f2

Please sign in to comment.