【发布时间】:2015-04-29 15:52:21
【问题描述】:
我正在尝试使用 spark 执行 K 最近邻搜索。
我有一个 RDD[Seq[Double]] 我打算返回一个 RDD[(Seq[Double],Seq[Seq[Double]])] 带有实际行和邻居列表
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)
})
它在 spark Submit 上给出以下错误
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.
我知道嵌套 RDD 是不可能的,但是我如何执行这样的操作,我可以将 RDD 中的每个元素与 RDD 中的每个其他元素进行比较
【问题讨论】:
-
如何比较RDD中的每个元素和RDD中的每个其他元素?
-
您可以使用
cartesian方法生成所有可能对的RDD -
最近有一个问题与此非常相似,但我现在找不到...
-
使用笛卡尔生成所有对。然后映射它以计算所有对之间的距离,第一个元素仍然是原始行值。 aggregateByKey,使用保持前“k”个最接近值的组合函数? (您可以在 combine 函数中包含欧几里得计算,这样会更快一些,但可能不太清楚)
标签: scala apache-spark nearest-neighbor