Github user sethah commented on a diff in the pull request:

    https://github.com/apache/spark/pull/15450#discussion_r84924203
  
    --- Diff: 
mllib/src/test/scala/org/apache/spark/mllib/clustering/KMeansSuite.scala ---
    @@ -64,30 +66,55 @@ class KMeansSuite extends SparkFunSuite with 
MLlibTestSparkContext {
         assert(model.clusterCenters.head ~== center absTol 1E-5)
       }
     
    -  test("no distinct points") {
    +  test("fewer distinct points than clusters") {
         val data = sc.parallelize(
           Array(
             Vectors.dense(1.0, 2.0, 3.0),
             Vectors.dense(1.0, 2.0, 3.0),
             Vectors.dense(1.0, 2.0, 3.0)),
           2)
    -    val center = Vectors.dense(1.0, 2.0, 3.0)
     
    -    // Make sure code runs.
    -    var model = KMeans.train(data, k = 2, maxIterations = 1)
    -    assert(model.clusterCenters.size === 2)
    -  }
    +    var model = KMeans.train(data, k = 2, maxIterations = 1, 
initializationMode = "random")
    +    assert(model.clusterCenters.length === 1)
     
    -  test("more clusters than points") {
    -    val data = sc.parallelize(
    -      Array(
    -        Vectors.dense(1.0, 2.0, 3.0),
    -        Vectors.dense(1.0, 3.0, 4.0)),
    -      2)
    +    model = KMeans.train(data, k = 2, maxIterations = 1, 
initializationMode = "k-means||")
    +    assert(model.clusterCenters.length === 1)
    +  }
     
    -    // Make sure code runs.
    -    var model = KMeans.train(data, k = 3, maxIterations = 1)
    -    assert(model.clusterCenters.size === 3)
    +    test("unique cluster centers") {
    +    val rng = new Random(seed)
    +    val numDistinctPoints = 10
    +    val points = (0 until numDistinctPoints).map(i => 
Vectors.dense(Array.fill(3)(rng.nextDouble)))
    +    val data = sc.parallelize(points.flatMap(Array.fill(1 + 
rng.nextInt(3))(_)), 2)
    +    val normedData = data.map(new VectorWithNorm(_))
    +
    +    // less centers than k
    --- End diff --
    
    Can we also test the "random" method here? I was going to suggest putting 
the test cases inside `Seq("k-means||", "random").foreach { initMode =>`, but 
we run the specific parallel case. Maybe just manually 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]

Reply via email to