4
4
Algorithm testing .
5
5
'''
6
6
7
+ import time
8
+
7
9
from src .KmeansAlgorithmV3 import KmeansAlgorithm
8
10
from src .Utility import Utility
9
11
10
- import time
12
+
11
13
class AlgorithmsTesting :
12
14
def testKmeansPureImpl (self ):
13
15
'''
@@ -24,7 +26,7 @@ def testKmeansPureImpl(self):
24
26
# needDimReduction = True
25
27
26
28
bestCostFunction = 999999999
27
- bestNumberOfClusters = 99999999
29
+ bestNumberOfClusters = 99999999
28
30
bestWorkingCopyDS = None
29
31
bestClusterMemberships = None
30
32
bestClusterCenters = None
@@ -33,15 +35,14 @@ def testKmeansPureImpl(self):
33
35
# Describe the data
34
36
utility .describeDS (originalDS )
35
37
36
-
37
38
kmeansAlgorithm = KmeansAlgorithm ()
38
39
# Call the K-mean function
39
40
maxNumberOfClusters = 15
40
41
prevoiusBestRunCostFunction = 999999999
41
42
t = time .localtime ()
42
- for numberOfClusters in range (2 ,maxNumberOfClusters ):
43
+ for numberOfClusters in range (2 , maxNumberOfClusters ):
43
44
workingCopyDS , clusterMemberships , clusterCenters , algorithmConvergeHistory , \
44
- costFunction = \
45
+ costFunction = \
45
46
kmeansAlgorithm .kmeansAlgorithmPureImpl (originalDS = originalDS ,
46
47
reclassifcationIterationLimit = 50 ,
47
48
stopLimit = 0.01 ,
@@ -58,11 +59,11 @@ def testKmeansPureImpl(self):
58
59
bestCostFunction = costFunction
59
60
60
61
# If no significant improvement, then break
61
- if prevoiusBestRunCostFunction - costFunction <= 0.02 :
62
+ if prevoiusBestRunCostFunction - costFunction <= 0.02 :
62
63
break
63
64
prevoiusBestRunCostFunction = costFunction
64
65
65
- print ("Time in execution: " , (time .localtime ().tm_sec - t .tm_sec ) )
66
+ print ("Time in execution: " , (time .localtime ().tm_sec - t .tm_sec ))
66
67
# Draw the data points along with the clusters centers )
67
68
utility .plot (bestClusterCenters , bestClusterMemberships , bestWorkingCopyDS ,
68
69
clusterBasedAlgorithmConvergeHistory )
0 commit comments