【问题标题】:MCC(Matthews Correlation Coefficient) on pysparkpyspark 上的 MCC(马修斯相关系数)
【发布时间】:2020-11-05 09:47:03
【问题描述】:

是否有在 pyspark 上获取 MCC(数学相关系数)的现有实现? 从混淆矩阵中实现一个很容易,但如果已经实现了一个,最好重复使用。

https://en.wikipedia.org/wiki/Matthews_correlation_coefficient

SKLearn API 相同: https://scikit-learn.org/stable/modules/generated/sklearn.metrics.matthews_corrcoef.html

【问题讨论】:

    标签: pyspark


    【解决方案1】:

    您可以将数据收集到名称节点并在那里使用 sklearn 的实现 ko MCC,但可能不是最好的主意。

    y_cap = [int(i['prediction']) for i in predictions.select('prediction').collect()]
    y = [int(i[condition]) for i in predictions.select(condition).collect()]
    confusion = confusion_matrix(y, y_cap)
    print(confusion)
    tn = np.float64(confusion[0][0])
    tp = np.float64(confusion[1][1])
    fp = np.float64(confusion[0][1])
    fn = np.float64(confusion[1][0])
    mcc = (tp * tn - fp * fn) / math.sqrt((tp + fp) * (tp + fn) * (tn + fp) * (tn + fn))
    print(mcc)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-11-13
      • 1970-01-01
      • 2012-12-07
      • 2015-09-05
      • 2021-07-13
      • 2018-06-15
      • 1970-01-01
      • 2019-01-16
      相关资源
      最近更新 更多