Skip to content

Commit 2086bdc

Browse files
committed
Log cluster center updates
1 parent ea9877c commit 2086bdc

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ import org.apache.spark.streaming.StreamingContext._
7676
@DeveloperApi
7777
class StreamingKMeansModel(
7878
override val clusterCenters: Array[Vector],
79-
val clusterCounts: Array[Long]) extends KMeansModel(clusterCenters) {
79+
val clusterCounts: Array[Long]) extends KMeansModel(clusterCenters) with Logging {
8080

8181
// do a sequential KMeans update on a batch of data
8282
def update(data: RDD[Vector], a: Double, units: String): StreamingKMeansModel = {
@@ -113,8 +113,14 @@ class StreamingKMeansModel(
113113
// store the new counts and centers
114114
counts(newP._1) = oldCount + newCount
115115
centers(newP._1) = Vectors.fromBreeze(updatedCentroid)
116-
}
117116

117+
// display the updated cluster centers
118+
val display = centers(newP._1).size match {
119+
case x if x > 100 => centers(newP._1).toArray.take(100).mkString("[", ",", "...")
120+
case _ => centers(newP._1).toArray.mkString("[", ",", "]")
121+
}
122+
logInfo("Cluster %d updated: %s ".format (newP._1, display))
123+
}
118124
new StreamingKMeansModel(centers, counts)
119125
}
120126

0 commit comments

Comments
 (0)