changeset 10:2405255d6a09 draft

Uploaded
author bimib
date Wed, 13 Feb 2019 04:46:14 -0500
parents 7c76e8e319c2
children d185506631e1
files Marea/marea_cluster.py
diffstat 1 files changed, 11 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/Marea/marea_cluster.py	Wed Feb 13 04:01:21 2019 -0500
+++ b/Marea/marea_cluster.py	Wed Feb 13 04:46:14 2019 -0500
@@ -540,13 +540,22 @@
 def f_cluster(resolve_rules):
     os.makedirs('cluster_out')
     args = process_args(sys.argv)
+    k_min = args.k_min
+    k_max = args.k_max
+    if k_min > k_max:
+         warning('k range boundaries inverted.\n')
+         tmp = k_min
+         k_min = k_max
+         k_max = tmp
+    else: 
+        warning('k range correct.\n')
     cluster_data = pd.DataFrame.from_dict(resolve_rules, orient = 'index')
     for i in cluster_data.columns:
         tmp = cluster_data[i][0]
         if tmp == None:
             cluster_data = cluster_data.drop(columns=[i])
     distorsion = []
-    for i in range(args.k_min, args.k_max+1):
+    for i in range(k_min, k_max+1):
         tmp_kmeans = KMeans(n_clusters = i,
                             n_init = 100, 
                             max_iter = 300,
@@ -559,7 +568,7 @@
         classe.to_csv(dest, sep = '\t', index = False,
                       header = ['Patient_ID', 'Class'])
     plt.figure(0)
-    plt.plot(range(args.k_min, args.k_max+1), distorsion, marker = 'o')
+    plt.plot(range(k_min, k_max+1), distorsion, marker = 'o')
     plt.xlabel('Number of cluster')
     plt.ylabel('Distorsion')
     plt.savefig(args.elbow, dpi = 240, format = 'pdf')
@@ -576,13 +585,6 @@
 
 def main():
     args = process_args(sys.argv)
-    if args.k_min > args.k_max:
-         warning('k range boundaries inverted.')
-         tmp = args.k_min
-         args.k_min = args.k_max
-         args.k_max = tmp
-    else: 
-        warning('k range correct.')
     if args.rules_selector == 'HMRcore':
         recon = pk.load(open(args.tool_dir + '/local/HMRcore_rules.p', 'rb'))
     elif args.rules_selector == 'Recon':