I solve the question with this code: import org.apache.spark.mllib.clustering.KMeans import org.apache.spark.mllib.linalg.Vectors
val data = sc.textFile("/opt/testAppSpark/data/height-weight.txt").map { line => Vectors.dense(line.split(' ').map(_.toDouble)) }.cache() val cluster = KMeans.train(data, 3, 20) val vectorsAndClusterIdx = data.map{ point => val prediction = cluster.predict(point) (point.toString, prediction) } vectorsAndClusterIdx.collect -- View this message in context: http://apache-spark-user-list.1001560.n3.nabble.com/MLlib-Show-an-element-in-RDD-Int-Iterable-Array-Double-tp21521p21522.html Sent from the Apache Spark User List mailing list archive at Nabble.com. --------------------------------------------------------------------- To unsubscribe, e-mail: user-unsubscr...@spark.apache.org For additional commands, e-mail: user-h...@spark.apache.org