How to use math.sqrt for DStream[(Double,Double)]?

一曲冷凌霜 提交于 2019-12-12 01:36:21

问题


For the streaming data DStream[(Double, Double)], how do I estimate the root mean squared error? See my code below. The line math.sqrt(summse) is where I have a problem (the code does not compile):

  def calculateRMSE(output: DStream[(Double, Double)], n: DStream[Long]): Double = {
        val summse = output.foreachRDD { rdd =>
          rdd.map {
              case pair: (Double, Double) =>
                val err = math.abs(pair._1 - pair._2);
                err*err
          }.reduce(_ + _)
        }
        math.sqrt(summse)
  }

UPDATE: The code doesn't compile: Cannot resolve reference sqrt with such signature. Expected: Double, Actual: Unit


回答1:


The method foreachRDD(...) returns unit so that is expected. According to the docs the result is written back to the this (output) DStream. I guess it's that you'll have to apply sqrt to.



来源:https://stackoverflow.com/questions/36978409/how-to-use-math-sqrt-for-dstreamdouble-double

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!