From 51130e0f8e3bc1266ff19547010fbcbd312f6180 Mon Sep 17 00:00:00 2001 From: Sharif Haason Date: Sun, 22 Mar 2026 17:33:05 -0400 Subject: [PATCH] Fix ConsensusCluster.fit_predict to use consensus matrix fit_predict() was ignoring the consensus clustering entirely and running a single AgglomerativeClustering on the raw data. Now it calls fit() to build the consensus matrix (H resamplings), then clusters on the distance matrix (1 - consensus_matrix) with metric='precomputed'. --- src/flowsom/models/consensus_cluster.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/flowsom/models/consensus_cluster.py b/src/flowsom/models/consensus_cluster.py index c189ea0..ac7eac5 100644 --- a/src/flowsom/models/consensus_cluster.py +++ b/src/flowsom/models/consensus_cluster.py @@ -103,10 +103,12 @@ def fit(self, data): return self def fit_predict(self, data): - """Predicts on the consensus matrix, for best found cluster number.""" - if self.z_score: - data = self._z_score(data) - return self.cluster(n_clusters=self.n_clusters, linkage=self.linkage).fit_predict(data) + """Builds consensus matrix via fit(), then clusters on it.""" + self.fit(data) + distance_matrix = 1 - self.Mk + return AgglomerativeClustering( + n_clusters=self.n_clusters, metric="precomputed", linkage=self.linkage + ).fit_predict(distance_matrix) def _z_score(self, data): data = zscore(data, axis=0)