Skip to content

Commit 7292c0f

Browse files
committed
V1
1 parent 1004e3a commit 7292c0f

File tree

3 files changed

+11
-11
lines changed

3 files changed

+11
-11
lines changed

src/AlgorithmsTestingV3.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@
44
Algorithm testing .
55
'''
66

7+
import time
8+
79
from src.KmeansAlgorithmV3 import KmeansAlgorithm
810
from src.Utility import Utility
911

10-
import time
12+
1113
class AlgorithmsTesting:
1214
def testKmeansPureImpl(self):
1315
'''
@@ -24,7 +26,7 @@ def testKmeansPureImpl(self):
2426
# needDimReduction = True
2527

2628
bestCostFunction = 999999999
27-
bestNumberOfClusters =99999999
29+
bestNumberOfClusters = 99999999
2830
bestWorkingCopyDS = None
2931
bestClusterMemberships = None
3032
bestClusterCenters = None
@@ -33,15 +35,14 @@ def testKmeansPureImpl(self):
3335
# Describe the data
3436
utility.describeDS(originalDS)
3537

36-
3738
kmeansAlgorithm = KmeansAlgorithm()
3839
# Call the K-mean function
3940
maxNumberOfClusters = 15
4041
prevoiusBestRunCostFunction = 999999999
4142
t = time.localtime()
42-
for numberOfClusters in range(2,maxNumberOfClusters):
43+
for numberOfClusters in range(2, maxNumberOfClusters):
4344
workingCopyDS, clusterMemberships, clusterCenters, algorithmConvergeHistory, \
44-
costFunction= \
45+
costFunction = \
4546
kmeansAlgorithm.kmeansAlgorithmPureImpl(originalDS=originalDS,
4647
reclassifcationIterationLimit=50,
4748
stopLimit=0.01,
@@ -58,11 +59,11 @@ def testKmeansPureImpl(self):
5859
bestCostFunction = costFunction
5960

6061
# If no significant improvement, then break
61-
if prevoiusBestRunCostFunction - costFunction <=0.02 :
62+
if prevoiusBestRunCostFunction - costFunction <= 0.02:
6263
break
6364
prevoiusBestRunCostFunction = costFunction
6465

65-
print("Time in execution: " , (time.localtime().tm_sec - t.tm_sec) )
66+
print("Time in execution: ", (time.localtime().tm_sec - t.tm_sec))
6667
# Draw the data points along with the clusters centers )
6768
utility.plot(bestClusterCenters, bestClusterMemberships, bestWorkingCopyDS,
6869
clusterBasedAlgorithmConvergeHistory)

src/KmeansAlgorithmV3.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ def kmeansAlgorithmPureImpl(_self, originalDS,
126126

127127
# points assignments on each cluster result
128128

129-
## print("Points assignments on each cluster result for iteration # ", currentIteration,
129+
## print("Points assignments on each cluster result for iteration # ", currentIteration,
130130
## ": ", clusterMemberships)
131131
# print("Points assignments on each cluster result for iteration # ",currentIteration,
132132
# ": ", clusterMemberships1)
@@ -221,14 +221,13 @@ def kmeansAlgorithmPureImpl(_self, originalDS,
221221

222222
costFunction = sumOfCostFunction / numberOfAssignedClusterPoints
223223

224-
225224
if costFunction <= stopLimit:
226225
isClusterCenterGetConverged = True
227226

228227
## print("algorithmConvergeHistory: ", algorithmConvergeHistory)
229228
algorithmConvergeHistory.append(costFunction)
230229
return workingCopyDS, clusterMemberships, clusterCenters, \
231-
algorithmConvergeHistory,costFunction
230+
algorithmConvergeHistory, costFunction
232231

233232

234233
def euclideanDistance(currentClusterCenter, currentPoint):

src/Utility.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ def plot(self, clusterCenters, clusterMemberships, workingCopyDS, algorithmConve
4848
plt.tight_layout()
4949
plt.show()
5050

51-
sns.lineplot(x=range(0+1, len(algorithmConvergeHistory)+1), y=algorithmConvergeHistory, marker='x')
51+
sns.lineplot(x=range(0 + 1, len(algorithmConvergeHistory) + 1), y=algorithmConvergeHistory, marker='x')
5252
plt.xlabel('X')
5353
plt.ylabel('Y')
5454
plt.show()

0 commit comments

Comments
 (0)