I am trying to search for the nearest neighbor K using a spark.
I have RDD [Seq [Double]] and I plan to return RDD [(Seq [Double], Seq [Seq [Double]])] with the actual row and list of neighbors
val out = data.map(row => {
val neighbours = data.top(num = 3)(new Ordering[Seq[Double]] {
override def compare(a:Seq[Double],b:Seq[Double]) = {
euclideanDistance(a,row).compare(euclideanDistance(b,row))*(-1)
}
})
(row,neighbours.toSeq)
})
And he gives the following error when turning on the spark.
15/04/29 21:15:39 WARN TaskSetManager: Lost task 0.0 in stage 1.0 (TID 2, 192.168.1.7): org.apache.spark.SparkException: RDD transformations and actions can only be invoked by the driver, not inside of other transformations; for example, rdd1.map(x => rdd2.values.count() * x) is invalid because the values transformation and count action cannot be performed inside of the rdd1.map transformation. For more information, see SPARK-5063.
I understand that embedding RDD is not possible, but how can I perform operations where I can compare every element in RDD with any other element in RDD
source
share