【发布时间】:2021-01-13 22:43:40
【问题描述】:
我正在尝试为决策树绘制 ROC 曲线。但是在计算混淆矩阵时,计算每个阈值需要花费太多时间。那么有没有更好的方法来计算矩阵。
【问题讨论】:
标签: python machine-learning pyspark roc confusion-matrix
我正在尝试为决策树绘制 ROC 曲线。但是在计算混淆矩阵时,计算每个阈值需要花费太多时间。那么有没有更好的方法来计算矩阵。
【问题讨论】:
标签: python machine-learning pyspark roc confusion-matrix
我建议你使用 scikit-learn 实现,你只需要提供一个包含真实值的数组和另一个包含预测值的数组:sklearn.metrics.roc_curve
【讨论】:
在你的混淆矩阵方法中, 您可以缓存预测以优化性能
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
祝你好运!
【讨论】: