代码2

mode给出模型计算出的test数据的similarity值,target是test数据本身给出的标准值,需要计算mode和target中00,01,10,11的个数

这个的zip还要清理一下

>>>a = [1,2,3]

>>>b = [9,6,1]

>>>for (i,j) in zip(a,b):

>>> print i+j

10

8

4

错误代码:

mode=open('/home/xbwang/Desktop/0.1another-results-dependency.1l.150d.epoch-1.0.35192.10005.pred','r')
target=open('/home/xbwang/xingyu/data/sick/test/sim.txt','r')
count00=0
count01=0
count10=0
count11=0
for tscore,mscore in zip(mode,target):
    #print(tscore)
    #print(mscore)
    #if(tscore == '0
'):
        #print('yes')
#if(tscore == '0'):
     #print('yes')
if(tscore=='0' and mscore=='0'): count00=count00+1 elif(tscore=='0' and mscore=='1'): count01=count01+1 elif(tscore=='1' and mscore=='0'): count10=count10+1 elif(tscore=='1' and mscore=='1'): count11=count11+1 print('count00:%d'%count00+' ') print('count01:%d'%count01+' ') print('count10:%d'%count10+' ') print('count11:%d'%count11+' ')

错误:print出来的值为0,0,0,0

正确代码:

mode=open('/home/xbwang/Desktop/0.1another-results-dependency.1l.150d.epoch-1.0.35192.10005.pred','r')
target=open('/home/xbwang/xingyu/data/sick/test/sim.txt','r')
count00=0
count01=0
count10=0
count11=0
for tscore,mscore in zip(mode,target):
    #print(tscore)
    #print(mscore)
    #if(tscore == '0
'):
        #print('yes')
    if(tscore=='0
' and mscore=='0
'):
        count00=count00+1
    elif(tscore=='0
' and mscore=='1
'):
        count01=count01+1
    elif(tscore=='1
' and mscore=='0
'):
        count10=count10+1
    elif(tscore=='1
' and mscore=='1
'):
        count11=count11+1
print('count00:%d'%count00+'
')
print('count01:%d'%count01+'
')
print('count10:%d'%count10+'
')
print('count11:%d'%count11+'
')
原文地址:https://www.cnblogs.com/ymjyqsx/p/6238143.html