Skip to content

Commit c446c58

Browse files
committed
documentation and numRuns warning change
1 parent 06d13ef commit c446c58

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

docs/mllib-clustering.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ guaranteed to find a globally optimal solution, and when run multiple times on
3333
a given dataset, the algorithm returns the best clustering result).
3434
* *initializationSteps* determines the number of steps in the k-means\|\| algorithm.
3535
* *epsilon* determines the distance threshold within which we consider k-means to have converged.
36+
* *initialModel* is an optional set of cluster centers used for initialization. If this parameter is supplied, only one run is performed.
3637

3738
**Examples**
3839

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -209,12 +209,15 @@ class KMeans private (
209209
val initStartTime = System.nanoTime()
210210

211211
// Only one run is allowed when initialModel is given
212-
val numRuns = if (initialModel.nonEmpty) 1 else runs
213-
logWarning("Ignoring runs; one run is allowed when initialModel is given.")
212+
val numRuns = if (initialModel.nonEmpty){
213+
if (runs >1 ) logWarning("Ignoring runs; one run is allowed when initialModel is given.")
214+
1
215+
} else runs
216+
214217

215218
val centers = initialModel match {
216219
case Some(kMeansCenters) => {
217-
Array(kMeansCenters.clusterCenters.map(s => new VectorWithNorm(s, Vectors.norm(s, 2.0))))
220+
Array(kMeansCenters.clusterCenters.map(s => new VectorWithNorm(s)))
218221
}
219222
case None => {
220223
if (initializationMode == KMeans.RANDOM) {

0 commit comments

Comments
 (0)