问题
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