From 28580d03d4f449f42d1e2a1533c0d3666af2e897 Mon Sep 17 00:00:00 2001 From: Evan Heidtmann Date: Tue, 26 Apr 2022 15:43:22 -0700 Subject: [PATCH] Use valid index for neighbors --- mlfromscratch/unsupervised_learning/dbscan.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/mlfromscratch/unsupervised_learning/dbscan.py b/mlfromscratch/unsupervised_learning/dbscan.py index 88da09ba..45f149fd 100644 --- a/mlfromscratch/unsupervised_learning/dbscan.py +++ b/mlfromscratch/unsupervised_learning/dbscan.py @@ -24,8 +24,9 @@ def _get_neighbors(self, sample_i): A sample_2 is considered a neighbor of sample_1 if the distance between them is smaller than epsilon """ neighbors = [] - idxs = np.arange(len(self.X)) - for i, _sample in enumerate(self.X[idxs != sample_i]): + for i, _sample in enumerate(self.X): + if i == sample_i: + continue distance = euclidean_distance(self.X[sample_i], _sample) if distance < self.eps: neighbors.append(i)