Skip to content

Commit d6fc822

Browse files
author
Guillaume Lemaitre
committed
Address issue #100 - Add exeption when no NN in majority class are found
1 parent a900985 commit d6fc822

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

imblearn/over_sampling/adasyn.py

+7
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,13 @@ def _sample(self, X, y):
131131

132132
# Compute the ratio of majority samples next to minority samples
133133
ratio_nn = np.sum(y[ind_nn[:, 1:]] == self.maj_c_, axis=1) / self.k
134+
# Check that we found at least some neighbours belonging to the
135+
# majority class
136+
if not np.sum(ratio_nn):
137+
raise RuntimeError('Not any neigbours belong to the majority'
138+
' class. This case will induce a NaN case with'
139+
' a division by zero. ADASYN is not suited for'
140+
' this specific dataset. Use SMOTE.')
134141
# Normalize the ratio
135142
ratio_nn /= np.sum(ratio_nn)
136143

0 commit comments

Comments
 (0)