[英]Exception:java.lang.Double cannot be cast to [D
I have logistic regression model and I want to calculating recall@25我有逻辑回归模型,我想计算recall@25
val predictionAndLabels = predicted
.select("prediction", "label")
.rdd.map(x => (x(0).asInstanceOf[Array[Double]], x(1)
.asInstanceOf[Array[Double]]))
val matrix = new RankingMetrics(predictionAndLabels)
Array(1, 25).foreach { k =>
println(s"Recall at $k = ${matrix.RecallAt(k)}")
}
this exception appear出现这个异常
java.lang.Double cannot be cast to [D
java.lang.Double 不能转换为 [D
How to solve it?如何解决?
RankingMetrics requires RDD(array, array) where as you are having RDD(double,double) which means you are passing the INVALID arguments. RankingMetrics 需要 RDD(array, array) ,因为你有 RDD(double,double) 这意味着你正在传递INVALID参数。
In General for Type conversion, map transformation used一般用于类型转换,使用映射转换
Assuming that predictionAndLabels.rdd type is RDD(double,double)假设 predictionAndLabels.rdd 类型为 RDD(double,double)
pairArrRDD = predictionAndLabels.rdd.map(x => (Array(x._1),Array(x._2))) //this is in scala pairArrRDD = predictionAndLabels.rdd.map(x => (Array(x._1),Array(x._2))) //这是scala
val matrix = new RankingMetrics( pairArrRDD ) val 矩阵 = 新排名指标( pairArrRDD )
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.