comparison COBRAxy/marea_cluster.py @ 317:4599fb23f25b draft

Uploaded
author francesco_lapi
date Wed, 04 Jun 2025 21:07:31 +0000
parents 38c9a958ea78
children
comparison
equal deleted inserted replaced
316:10e9a5a86d37 317:4599fb23f25b
57 default = 7, 57 default = 7,
58 help = 'choose maximum cluster number to be generated') 58 help = 'choose maximum cluster number to be generated')
59 59
60 parser.add_argument('-el', '--elbow', 60 parser.add_argument('-el', '--elbow',
61 type = str, 61 type = str,
62 default = 'False', 62 default = 'false',
63 choices = ['True', 'False'], 63 choices = ['true', 'false'],
64 help = 'choose if you want to generate an elbow plot for kmeans') 64 help = 'choose if you want to generate an elbow plot for kmeans')
65 65
66 parser.add_argument('-si', '--silhouette', 66 parser.add_argument('-si', '--silhouette',
67 type = str, 67 type = str,
68 default = 'False', 68 default = 'false',
69 choices = ['True', 'False'], 69 choices = ['true', 'false'],
70 help = 'choose if you want silhouette plots') 70 help = 'choose if you want silhouette plots')
71 71
72 parser.add_argument('-td', '--tool_dir', 72 parser.add_argument('-td', '--tool_dir',
73 type = str, 73 type = str,
74 required = True, 74 required = True,
222 """ 222 """
223 if not os.path.exists(args.output_path): 223 if not os.path.exists(args.output_path):
224 os.makedirs(args.output_path) 224 os.makedirs(args.output_path)
225 225
226 226
227 if elbow == 'True': 227 if elbow == 'true':
228 elbow = True 228 elbow = True
229 else: 229 else:
230 elbow = False 230 elbow = False
231 231
232 if silhouette == 'True': 232 if silhouette == 'true':
233 silhouette = True 233 silhouette = True
234 else: 234 else:
235 silhouette = False 235 silhouette = False
236 236
237 range_n_clusters = [i for i in range(k_min, k_max+1)] 237 range_n_clusters = [i for i in range(k_min, k_max+1)]
475 475
476 for i in range(len(labels)): 476 for i in range(len(labels)):
477 prefix = '' 477 prefix = ''
478 if (i + k_min == best): 478 if (i + k_min == best):
479 prefix = '_BEST' 479 prefix = '_BEST'
480 if silhouette == 'True': 480 if silhouette == 'true':
481 silhouette_draw(dataset, labels[i], i + k_min, f'{args.output_path}/silhouette_with_' + str(i + k_min) + prefix + '_clusters.png') 481 silhouette_draw(dataset, labels[i], i + k_min, f'{args.output_path}/silhouette_with_' + str(i + k_min) + prefix + '_clusters.png')
482 482
483 for i in range(len(labels)): 483 for i in range(len(labels)):
484 if (i + k_min == best): 484 if (i + k_min == best):
485 labels = labels[i] 485 labels = labels[i]