Skip to content

Commit ff2a671

Browse files
authored
Merge pull request #67 from dvro/test_min_cluster_size
Added test_min_cluster_size
2 parents b53d164 + 1ad80d9 commit ff2a671

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

hdbscan/tests/test_hdbscan.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"""
55
#import pickle
66
from nose.tools import assert_less
7+
from nose.tools import assert_greater_equal
78
import numpy as np
89
from scipy.spatial import distance
910
from scipy import sparse
@@ -217,7 +218,6 @@ def test_hdbscan_best_balltree_metric():
217218
n_clusters_2 = len(set(labels)) - int(-1 in labels)
218219
assert_equal(n_clusters_2, n_clusters)
219220

220-
221221
def test_hdbscan_no_clusters():
222222
labels, p, persist, ctree, ltree, mtree = hdbscan(X, min_cluster_size=len(X)+1)
223223
n_clusters_1 = len(set(labels)) - int(-1 in labels)
@@ -226,7 +226,19 @@ def test_hdbscan_no_clusters():
226226
labels = HDBSCAN(min_cluster_size=len(X)+1).fit(X).labels_
227227
n_clusters_2 = len(set(labels)) - int(-1 in labels)
228228
assert_equal(n_clusters_2, 0)
229-
229+
230+
def test_hdbscan_min_cluster_size():
231+
for min_cluster_size in range(2, len(X)+1, 1):
232+
labels, p, persist, ctree, ltree, mtree = hdbscan(X, min_cluster_size=min_cluster_size)
233+
true_labels = [label for label in labels if label != -1]
234+
if len(true_labels) != 0:
235+
assert_greater_equal(np.min(np.bincount(true_labels)), min_cluster_size)
236+
237+
labels = HDBSCAN(min_cluster_size=min_cluster_size).fit(X).labels_
238+
true_labels = [label for label in labels if label != -1]
239+
if len(true_labels) != 0:
240+
assert_greater_equal(np.min(np.bincount(true_labels)), min_cluster_size)
241+
230242
def test_hdbscan_callable_metric():
231243
# metric is the function reference, not the string key.
232244
metric = distance.euclidean

0 commit comments

Comments
 (0)