Skip to content
Closed
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

package org.apache.spark.ml.clustering

import scala.collection.mutable

import org.apache.spark.{SparkException, SparkFunSuite}
import org.apache.spark.ml.util.DefaultReadWriteTest
import org.apache.spark.mllib.util.MLlibTestSparkContext
Expand Down Expand Up @@ -76,23 +78,31 @@ class PowerIterationClusteringSuite extends SparkFunSuite
.setMaxIter(40)
.setWeightCol("weight")
.assignClusters(data)
val localAssignments = assignments
.select('id, 'cluster)
.as[(Long, Int)].collect().toSet
val expectedResult = (0 until n1).map(x => (x, 1)).toSet ++
(n1 until n).map(x => (x, 0)).toSet
assert(localAssignments === expectedResult)
.select("id", "cluster")
.as[(Long, Int)]
.collect()

val predictions = Array.fill(2)(mutable.Set.empty[Long])
assignments.foreach{
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This might fail the style checker -- need a space before the brace. Looks good otherwise. Let's see if the test passes.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have added the space. Thank you.

case (id, cluster) => predictions(cluster) += id
}
assert(predictions.toSet === Set((0 until n1).toSet, (n1 until n).toSet))

val assignments2 = new PowerIterationClustering()
.setK(2)
.setMaxIter(10)
.setInitMode("degree")
.setWeightCol("weight")
.assignClusters(data)
val localAssignments2 = assignments2
.select('id, 'cluster)
.as[(Long, Int)].collect().toSet
assert(localAssignments2 === expectedResult)
.select("id", "cluster")
.as[(Long, Int)]
.collect()

val predictions2 = Array.fill(2)(mutable.Set.empty[Long])
assignments2.foreach {
case (id, cluster) => predictions2(cluster) += id
}
assert(predictions2.toSet === Set((0 until n1).toSet, (n1 until n).toSet))
}

test("supported input types") {
Expand Down