From 34dfdae4a58be5bdd51f07f12de132ec09c610b6 Mon Sep 17 00:00:00 2001 From: DIANE <abderrahim.diane@cefe.cnrs.fr> Date: Mon, 15 Apr 2024 11:59:08 +0200 Subject: [PATCH] clusters name --- Class_Mod/KMEANS_.py | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/Class_Mod/KMEANS_.py b/Class_Mod/KMEANS_.py index ab9e22b..526a435 100644 --- a/Class_Mod/KMEANS_.py +++ b/Class_Mod/KMEANS_.py @@ -19,13 +19,6 @@ class Sk_Kmeans: def fit_optimal(self, nclusters): model = KMeans(n_clusters = nclusters, init = 'k-means++', random_state = 42) model.fit(self.x) - yp = model.predict(self.x) - num_colors = nclusters - colors = ['#' + ''.join([random.choice('0123456789ABCDEF') for _ in range(6)]) for _ in range(num_colors)] - col = np.array(['#' + ''.join([random.choice('0123456789ABCDEF') for _ in range(6)]) for _ in range(self.x.shape[0])]) - for i in range(nclusters): - ss = np.where(yp==i) - col[ss] = colors[i] - - - return self.x, col \ No newline at end of file + yp = model.predict(self.x)+1 + clu = [f'cluster#{i}' for i in yp] + return self.x, clu \ No newline at end of file -- GitLab