From ba2f0a9742805a6793330ed11f1b5b92b390b883 Mon Sep 17 00:00:00 2001 From: chaithumcn3 Date: Tue, 17 Dec 2019 17:56:31 +0530 Subject: [PATCH] kNN with kmeans++ code --- kNN.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/kNN.py b/kNN.py index 65eae48..4c92757 100644 --- a/kNN.py +++ b/kNN.py @@ -6,6 +6,7 @@ # 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)] @@ -13,7 +14,7 @@ def kMeansPPlusInitalization(data, distancematrix, numclusters): while numclusters: initialpoints[numclusters] = getNextPoint(data.keys(), distancematrix, initialpoints) numclusters -=1 - + return initialpoints @@ -29,6 +30,8 @@ def getNextPoint(keys, distancematrix, initialpoints): minimum = distancematrix[i][j] genDistanceDict[i] = minimum + + #code for prob. pick to be written