Skip to content

Commit

Permalink
kNN with kmeans++ code
Browse files Browse the repository at this point in the history
  • Loading branch information
metalcyanide committed Dec 17, 2019
1 parent 4bae36c commit ba2f0a9
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion kNN.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@
# Now that the initial centers have been chosen, proceed using standard k-means clustering.

#kmeans++ initialization of labels. data being a dictionary

def kMeansPPlusInitalization(data, distancematrix, numclusters):
initialpoints = dict()
initialpoints[numclusters] = [random.sample(data.keys(),1)]
numclusters -=1
while numclusters:
initialpoints[numclusters] = getNextPoint(data.keys(), distancematrix, initialpoints)
numclusters -=1

return initialpoints


Expand All @@ -29,6 +30,8 @@ def getNextPoint(keys, distancematrix, initialpoints):
minimum = distancematrix[i][j]
genDistanceDict[i] = minimum



#code for prob. pick to be written


Expand Down

0 comments on commit ba2f0a9

Please sign in to comment.