Github user srowen commented on a diff in the pull request: https://github.com/apache/spark/pull/14937#discussion_r77489012 --- Diff: mllib/src/main/scala/org/apache/spark/mllib/clustering/KMeans.scala --- @@ -211,17 +220,79 @@ class KMeans private ( + " parent RDDs are also uncached.") } - // Compute squared norms and cache them. - val norms = data.map(Vectors.norm(_, 2.0)) - norms.persist() - val zippedData = data.zip(norms).map { case (v, norm) => - new VectorWithNorm(v, norm) + val zippedData = data.map { x => new VectorWithNorm(x) } + + val initStartTime = System.nanoTime() + + val centers = initialModel match { + case Some(kMeansCenters) => + kMeansCenters.clusterCenters.map(new VectorWithNorm(_)) + case None => + if (initializationMode == KMeans.RANDOM) { + initRandom(zippedData) + } else { + initKMeansParallel(zippedData) + } + } + + val initTimeInSeconds = (System.nanoTime() - initStartTime) / 1e9 + logInfo(s"Initialization with $initializationMode took " + "%.3f".format(initTimeInSeconds) + --- End diff -- Another nit while I'm here -- this could be one `f"..."` format string
--- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastruct...@apache.org or file a JIRA ticket with INFRA. --- --------------------------------------------------------------------- To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org For additional commands, e-mail: reviews-h...@spark.apache.org