gpt4 book ai didi

Python:计算 TP、FP、FN и TN

转载 作者:行者123 更新时间:2023-11-30 09:36:37 25 4
gpt4 key购买 nike

我有具有真实类别和类别的数据框,这是通过某种算法预测的。

     true  pred
0 1 0
1 1 1
2 1 1
3 0 0
4 1 1

我尝试使用

def classification(y_actual, y_hat):
TP = 0
FP = 0
TN = 0
FN = 0

for i in range(len(y_hat)):
if y_actual[i] == y_hat[i] == 1:
TP += 1
for i in range(len(y_hat)):
if y_actual[i] == 1 and y_actual != y_hat[i]:
FP += 1
for i in range(len(y_hat)):
if y_actual[i] == y_hat[i] == 0:
TN += 1
for i in range(len(y_hat)):
if y_actual[i] == 0 and y_actual != y_hat[i]:
FN += 1

return(TP, FP, TN, FN)

但它返回了我

ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all(). How can I fix that or maybe there are the better decision?

最佳答案

我使用来自 sklearn.metricsconfusion_matrix,它返回我需要的矩阵。

关于Python:计算 TP、FP、FN и TN,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39733934/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com