简体   繁体   English

计算 TP、FP、TN、FN 值

[英]Calculating TP, FP, TN, FN values

I am trying to build a very simple program for calculating TP/FP/FN/TN for 2 strings (predicted secondary protein structure vs proven secondary protein structure), but it does not calculating them correctly.我正在尝试构建一个非常简单的程序来计算 2 个字符串的 TP/FP/FN/TN(预测的二级蛋白质结构与已证明的二级蛋白质结构),但它没有正确计算它们。 What is it that I am missing?我错过了什么?

actual_str = '*ΟΟΟΟΟΟ******////////////**//////////*****////ΟΟΟΟΟΟΟΟΟ***'
predicted_str = '****--********/////////-----//////****----**-ΟΟΟΟΟΟΟ/-****'

TP = 0
FP = 0
TN = 0
FN = 0

for i in range(len(predicted_str)): 
    if predicted_str[i]==actual_str[i]=='O':
        TP += 1
        
    if predicted_str[i]!='O' and actual_str[i]=='O': 
        FP += 1
        
    if predicted_str[i]==actual_str[i]=='/' or predicted_str[i]==actual_str[i]=='*':
        TN += 1
        
    if predicted_str[i]=='O' and actual_str[i]!='O':
        FN += 1
        
    if predicted_str[i]=='-': #just ignore the '-' and move on to the next
        i+=1

print(TP, FP, TN, FN)
    

Output: 0 0 26 0 Output:0 0 26 0

This is a strange one, but try to copy one of the 'O' character used in the actual_str or predicted_str variables, and paste that in your if-statements.这是一个奇怪的问题,但请尝试复制在actual_strpredicted_str变量中使用的“O”字符之一,并将其粘贴到您的 if 语句中。 I think there is a mismatch, even though they look identical.我认为存在不匹配,即使它们看起来相同。

Also the last if-statement is not necessary.最后一个 if 语句也不是必需的。

As commented before, the characters you are using are different, it mixes the greek letter O omicron and the Latin o capital.如前所述,您使用的字符不同,它混合了希腊字母 O omicron 和拉丁字母 o 大写字母。

https://apps.timwhitlock.info/unicode/inspect?s=%CE%9F https://apps.timwhitlock.info/unicode/inspect?s=%CE%9F

In addition instead of compare it by index, it make sense to use a zip operator in this usecase:除了按索引进行比较之外,在这个用例中使用 zip 运算符是有意义的:

for (actual, predicted) in zip(actual_str, predicted_str):
   if (..

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

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