【问题标题】:ROC Curve for decision tree决策树的 ROC 曲线
【发布时间】:2021-01-13 22:43:40
【问题描述】:

我正在尝试为决策树绘制 ROC 曲线。但是在计算混淆矩阵时,计算每个阈值需要花费太多时间。那么有没有更好的方法来计算矩阵。

【问题讨论】:

    标签: python machine-learning pyspark roc confusion-matrix


    【解决方案1】:

    我建议你使用 scikit-learn 实现,你只需要提供一个包含真实值的数组和另一个包含预测值的数组:sklearn.metrics.roc_curve

    【讨论】:

    • OP 显然是在一个“大数据”框架中:他们使用的是 Pyspark,这意味着所涉及的数据帧无法放入单个机器的内存中,因此 scikit-learn 在这里不适用。跨度>
    【解决方案2】:

    在你的混淆矩阵方法中, 您可以缓存预测以优化性能

     def confusion_matrix(predictions):
         # Calculate the elements of the confusion matrix
        predictions.cache()
        TN = predictions.filter('prediction = 0 AND label = 0').count()
        TP = predictions.filter('prediction = 1 AND label = 1').count()
        FN = predictions.filter('prediction = 0 AND label = 1').count()
        FP = predictions.filter('prediction = 1 AND label = 0').count()
        predictions.unpersist()
        return TP,TN,FP,FN
    

    祝你好运!

    【讨论】:

      猜你喜欢
      • 2016-05-26
      • 2018-01-04
      • 2020-10-05
      • 2020-05-18
      • 1970-01-01
      • 2019-02-27
      • 2018-01-03
      • 2019-12-26
      • 2014-07-20
      相关资源
      最近更新 更多