Skip to content

Commit 12ce731

Browse files
author
Li Jingqin
committed
Init cluster centers with norm, which save computings
1 parent 01eb404 commit 12ce731

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

mllib/src/main/scala/org/apache/spark/mllib/clustering/KMeansModel.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ class KMeansModel (val clusterCenters: Array[Vector]) extends Serializable {
2929

3030
/** Total number of clusters. */
3131
def k: Int = clusterCenters.length
32+
val ccWithNorm: Array[BreezeVectorWithNorm] = clusterCenters.map(new BreezeVectorWithNorm(_))
3233

3334
/** Returns the cluster index that a given point belongs to. */
3435
def predict(point: Vector): Int = {
@@ -43,7 +44,7 @@ class KMeansModel (val clusterCenters: Array[Vector]) extends Serializable {
4344
}
4445

4546
def predict2(point: Vector): (Int, Double) = {
46-
KMeans.findClosest(clusterCentersWithNorm, new BreezeVectorWithNorm(point))
47+
KMeans.findClosest(ccWithNorm, new BreezeVectorWithNorm(point))
4748
}
4849

4950
/** Maps given points to their cluster indices. */

0 commit comments

Comments
 (0)