繁体   English   中英

使用 for 循环创建阈值评估

[英]using for-loop to create threshold evaluation

我想在这里使用 for 循环来自动运行所有阈值? 如何使用阈值在这里创建一个 for 循环?

y_pred_binary = []
thresholds = [0.4, 0.45, 0.50, 0.55, 0.60, 0.65]

for pred in y_pred:
    if pred > 0.5:
        y_pred_binary.append(1)
    else:
        y_pred_binary.append(0)

通过使用此命令:

print(classification_report(target, y_pred_binary, labels=[0, 1]))
print(evalute(target, y_pred, y_pred_binary))

我想打印出每个阈值的所有结果:例如:

#classification report 

          precision    recall  f1-score   support

           0       0.76      0.20      0.31      2162
           1       0.54      0.94      0.68      2162

    accuracy                           0.57      4324
   macro avg       0.65      0.57      0.50      4324
weighted avg       0.65      0.57      0.50      4324


#result of evaluate function I made 

Accuracy: 0.567
f1: 0.684
recall: 0.937
precision: 0.538
rocauc: 0.769
[[ 425 1737]
 [ 136 2026]]

您正在寻找以下实现吗? 请详细说明要求。

y_pred_binary = []
thresholds = [0.4, 0.45, 0.50, 0.55, 0.60, 0.65]

for thresh in thresholds :
    for pred in y_pred:
        if pred > thresh :
            y_pred_binary.append(1)
        else:
            y_pred_binary.append(0)

编辑:


thresholds = [0.4, 0.45, 0.50, 0.55, 0.60, 0.65]
y_pred_binary = [[0 for i in range(len(y_pred))] for j in range(len(thresholds) )]

for a  in range(len(thresholds)) :
    for b in range(len(y_pred)):
        if y_pred[b]> thresholds[a]:
            y_pred_binary[a][b] =1
        

y_pred_binary 现在是所有阈值的二维数组

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM