我尝试计算按字段分组的 AUC(ROC 下的面积)id。给出以下数据:
# Within each key-value pair
# key is "id"
# value is a list of (score, label)
data = sc.parallelize(
[('id1', [(0.5, 1.0), (0.6, 0.0), (0.7, 1.0), (0.8, 0.0)),
('id2', [(0.5, 1.0), (0.6, 0.0), (0.7, 1.0), (0.8, 0.0))
]
Run Code Online (Sandbox Code Playgroud)
这BinaryClassificationMetrics可以计算给定列表的 AUC (score, label)。
我想通过键计算 AUC(即id1, id2)计算 AUC。但是如何class通过键将 a“映射”到 RDD 呢?
我尝试将其包装BinaryClassificationMetrics在一个函数中:
def auc(scoreAndLabels):
return BinaryClassificationMetrics(scoreAndLabels).areaUnderROC
Run Code Online (Sandbox Code Playgroud)
然后将包装函数映射到每个值:
data.groupByKey()\
.mapValues(auc)
Run Code Online (Sandbox Code Playgroud)
但列表实际上(score, label)是在ResultIterablemapValues() …