Skip to content

Commit 00220dd

Browse files
committed
Shouldn't have size zero clusters -- but we should handle them gracefully none the less.
1 parent a37fa97 commit 00220dd

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

hdbscan/validity.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,9 @@ def validity_index(X, labels, metric='euclidean',
324324

325325
for cluster_id in range(max_cluster_id):
326326

327+
if np.sum(labels == cluster_id) == 0:
328+
continue
329+
327330
mr_distances, core_distances[
328331
cluster_id] = all_points_mutual_reachability(
329332
X,
@@ -339,6 +342,10 @@ def validity_index(X, labels, metric='euclidean',
339342
density_sparseness[cluster_id] = mst_edges[cluster_id].T[2].max()
340343

341344
for i in range(max_cluster_id):
345+
346+
if np.sum(labels == i) == 0:
347+
continue
348+
342349
internal_nodes_i = mst_nodes[i]
343350
for j in range(i + 1, max_cluster_id):
344351
internal_nodes_j = mst_nodes[j]
@@ -354,6 +361,10 @@ def validity_index(X, labels, metric='euclidean',
354361
result = 0
355362

356363
for i in range(max_cluster_id):
364+
365+
if np.sum(labels == i) == 0:
366+
continue
367+
357368
min_density_sep = density_sep[i].min()
358369
cluster_validity_indices[i] = (
359370
(min_density_sep - density_sparseness[i]) /

0 commit comments

Comments
 (0)