2626# STEP 5: Update epicenters
2727# STEP 6: Repeat 3 until epicenters don't change
2828
29+
2930def train (csvfile ):
3031
3132 # STEP 1
@@ -42,24 +43,26 @@ def train(csvfile):
4243 glob_cluster_list = []
4344 glob_nos_clusters = 0
4445
45- glob_nos_clusters = int (input ("\n Enter the number of clusters clearly visible in the plot: " ))
46- for i in range (1 , glob_nos_clusters + 1 ):
46+ glob_nos_clusters = int (
47+ input ("\n Enter the number of clusters clearly visible in the plot: " )
48+ )
49+ for i in range (1 , glob_nos_clusters + 1 ):
4750 temp_dict = {}
48- temp_dict ["epi_x" ] = random .randint (1 ,10 )
49- temp_dict ["epi_y" ] = random .randint (1 ,10 )
50- temp_dict [' points' ] = []
51- temp_dict [' title' ] = i
51+ temp_dict ["epi_x" ] = random .randint (1 , 10 )
52+ temp_dict ["epi_y" ] = random .randint (1 , 10 )
53+ temp_dict [" points" ] = []
54+ temp_dict [" title" ] = i
5255
5356 glob_cluster_list .append (temp_dict )
54- #print("- Initialized ", glob_nos_clusters, " clusters")
57+ # print("- Initialized ", glob_nos_clusters, " clusters")
5558
56- #print ("INIT DEBUG \n")
57- #for k in glob_cluster_list:
59+ # print ("INIT DEBUG \n")
60+ # for k in glob_cluster_list:
5861 # print (k['epi_x'], k['epi_y'], end=" ")
5962 # print()
6063
61- for l in range (glob_nos_points * 5 ):
62- #Run assignment
64+ for l in range (glob_nos_points * 5 ):
65+ # Run assignment
6366 glob_points_list = points .nextassign (glob_cluster_list , glob_points_list )
6467 glob_cluster_list = clusters .update_epi (glob_cluster_list , glob_points_list )
6568
@@ -69,33 +72,33 @@ def train(csvfile):
6972 new_x = new_y = 0
7073 change = 0
7174
72- #record previous epicenters:
75+ # record previous epicenters:
7376 for i in glob_cluster_list :
74- prev_x += i [' epi_x' ]
75- prev_y += i [' epi_y' ]
77+ prev_x += i [" epi_x" ]
78+ prev_y += i [" epi_y" ]
7679
77- #Run assignment
80+ # Run assignment
7881 glob_points_list = points .nextassign (glob_cluster_list , glob_points_list )
7982 glob_cluster_list = clusters .update_epi (glob_cluster_list , glob_points_list )
8083
81- #record new epicenters:
84+ # record new epicenters:
8285 for j in glob_cluster_list :
83- new_x += j [' epi_x' ]
84- new_y += j [' epi_y' ]
86+ new_x += j [" epi_x" ]
87+ new_y += j [" epi_y" ]
8588
8689 change = abs (prev_x - new_x ) + abs (prev_y - new_y )
8790 if change == 0 :
8891 break
8992
90- print ("FIN DEBUG \n " )
93+ print ("FIN DEBUG \n " )
9194 for k in glob_cluster_list :
92- print (k [' epi_x' ], k [' epi_y' ], end = " " )
93- print ()
94- #print ("\n\nPOINTS:: ")
95- #for p in glob_points_list:
95+ print (k [" epi_x" ], k [" epi_y" ], end = " " )
96+ print ()
97+ # print ("\n\nPOINTS:: ")
98+ # for p in glob_points_list:
9699 # print(p)
97100
98- glob_cluster_list = clusters .finalize (glob_cluster_list ,glob_points_list )
101+ glob_cluster_list = clusters .finalize (glob_cluster_list , glob_points_list )
99102
100103 print ("Hopefully, now the epicenters are correctly arranged" )
101104 global glob_trained
@@ -104,36 +107,36 @@ def train(csvfile):
104107
105108print (" ** \n Welcome to KMeansExample.\n **\n " )
106109csvfile = input ("Please enter the csv file containing the student records: " )
107- #csvfile = 'data/simple.csv'
110+ # csvfile = 'data/simple.csv'
108111print ("Working on student records at " , csvfile , " .." )
109112
110113while True :
111- print ("\n \n " )
112- print (" * (1) for previewing the records" )
113- print (" * (2) for proceeding with training" )
114- print (" * (3) for getting a prediction" )
115- print (" * (4) for Exiting the predictor" )
114+ print ("\n \n " )
115+ print (" * (1) for previewing the records" )
116+ print (" * (2) for proceeding with training" )
117+ print (" * (3) for getting a prediction" )
118+ print (" * (4) for Exiting the predictor" )
116119
117120 if glob_trained == True :
118- print (" * (5) for Rich preview" )
119- print (" * (6) for Naming clusters" )
120- print (" * (7) for Viewing points" )
121+ print (" * (5) for Rich preview" )
122+ print (" * (6) for Naming clusters" )
123+ print (" * (7) for Viewing points" )
121124
122125 i = int (input ("Enter action: " ))
123126
124127 if i == 1 :
125128 print ("Previewing the records: " )
126129 preview .preview (csvfile )
127-
130+
128131 elif i == 2 :
129132 train (csvfile )
130133
131134 elif i == 3 :
132135 predict .predict (glob_cluster_list )
133-
136+
134137 elif i == 4 :
135138 break
136-
139+
137140 elif i == 5 :
138141 pass
139142 preview .richprev (glob_cluster_list )
@@ -143,7 +146,7 @@ def train(csvfile):
143146 glob_cluster_list = ret [0 ]
144147 glob_named = ret [1 ]
145148 print ("Names set." )
146-
149+
147150 elif i == 7 :
148151 points .view (glob_cluster_list )
149152
0 commit comments