Github user yinxusen commented on a diff in the pull request:
https://github.com/apache/spark/pull/11119#discussion_r52392336
--- Diff:
mllib/src/test/scala/org/apache/spark/ml/clustering/KMeansSuite.scala ---
@@ -106,6 +106,38 @@ class KMeansSuite extends SparkFunSuite with
MLlibTestSparkContext with DefaultR
val kmeans = new KMeans()
testEstimatorAndModelReadWrite(kmeans, dataset,
KMeansSuite.allParamSettings, checkModelData)
}
+
+ test("Initialize using given cluster centers") {
+ val points = Array(
+ Vectors.dense(0.0, 0.0, 0.0),
+ Vectors.dense(1.0, 1.0, 1.0),
+ Vectors.dense(2.0, 2.0, 2.0),
+ Vectors.dense(3.0, 3.0, 3.0),
+ Vectors.dense(4.0, 4.0, 4.0)
+ )
+
+ // creating an initial model
+ val initialModel = new KMeansModel("test model", new
MLlibKMeansModel(points))
+
+ val predictionColName = "kmeans_prediction"
+ val kmeans = new KMeans()
+ .setK(k)
+ .setPredictionCol(predictionColName)
+ .setSeed(1)
+ .setInitialModel(initialModel)
+ val model = kmeans.fit(dataset)
+ assert(model.clusterCenters.length === k)
+
--- End diff --
Good catch, I'll add it.
---
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 [email protected] or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]