0
试图解决Spark中聚类算法中测量模型评估统计(精度和召回)的问题。 Original inspiration from cross validated为成对重叠为基础的集群评估潜在的反应。聚类中的精度和召回(在Spark,Scala中的应用)
创建这个样本测试数据,我能够得到总的预测肯定。
你将如何去计算真正的积极?特别是对火花数据帧进行转换以获得结果。非常感谢任何灵感。
+-----+----------+
|label| cluster |
+-----+----------+
| x| 1|
| x| 1|
| x| 1|
| x| 1|
| x| 1|
| x| 2|
| x| 3|
| x| 3|
| o| 1|
| o| 2|
| o| 2|
| o| 2|
| o| 2|
| d| 2|
| d| 3|
| d| 3|
| d| 3|
+-----+----------+
// the nCk function to be used as a UDF
def choose(n: Int, k: Int): Int ={
if (k==0) 1 else (n * choose(n-1, k-1))/k
}
val udf_choose = udf(choose _)
// the combined sum of true positive and false positive
val tp_fp = (df.groupBy("cluster")
.count()
.filter($"count" > 1)
.withColumn("combinations", udf_choose($"count", lit(2)))
.agg(sum("combinations"))
.first().getLong(0))
// How to calculate True Positive?
** OUTPUT **
tp_fp: Long = 40