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