Skip to content

Commit 66733c4

Browse files
Micky774jeremiedbb
andauthored
FIX Updated hdbscan stability calculation to avoid implicit casting (scikit-learn#26546)
Co-authored-by: jeremie du boisberranger <jeremiedbb@yahoo.fr>
1 parent ab48408 commit 66733c4

File tree

1 file changed

+4
-8
lines changed

1 file changed

+4
-8
lines changed

sklearn/cluster/_hdbscan/_tree.pyx

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -246,10 +246,10 @@ cdef dict _compute_stability(
246246
cnp.intp_t parent, cluster_size, result_index, idx
247247
cnp.float64_t lambda_val
248248
CONDENSED_t condensed_node
249-
cnp.float64_t[:, :] result_pre_dict
250249
cnp.intp_t largest_child = condensed_tree['child'].max()
251250
cnp.intp_t smallest_cluster = np.min(parents)
252251
cnp.intp_t num_clusters = np.max(parents) - smallest_cluster + 1
252+
dict stability_dict = {}
253253

254254
largest_child = max(largest_child, smallest_cluster)
255255
births = np.full(largest_child + 1, np.nan, dtype=np.float64)
@@ -270,14 +270,10 @@ cdef dict _compute_stability(
270270
result_index = parent - smallest_cluster
271271
result[result_index] += (lambda_val - births[parent]) * cluster_size
272272

273-
result_pre_dict = np.vstack(
274-
(
275-
np.arange(smallest_cluster, np.max(parents) + 1),
276-
result
277-
)
278-
).T
273+
for idx in range(num_clusters):
274+
stability_dict[idx + smallest_cluster] = result[idx]
279275

280-
return dict(result_pre_dict)
276+
return stability_dict
281277

282278

283279
cdef list bfs_from_cluster_tree(

0 commit comments

Comments
 (0)