From 10cc6f2f3c4d272ec7ed756cacd6081954653fd9 Mon Sep 17 00:00:00 2001 From: Xiangzhuang Shen Date: Sun, 27 Oct 2024 12:15:06 +0800 Subject: [PATCH] fix: leaf node return edge length 0 --- toyml/ensemble/iforest.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/toyml/ensemble/iforest.py b/toyml/ensemble/iforest.py index 16162a3..98e7666 100644 --- a/toyml/ensemble/iforest.py +++ b/toyml/ensemble/iforest.py @@ -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_)