0

I wrote a code like below

t_p=0
f_p=0
f_n=0
t_n=0

while True:
    line=raw_input()
    if not line:
        break
    actual,predicted=line.split(',')
    print actual, predicted
    if (actual==1 and predicted==1):
        t_p+=50
        print "tp", t_p
    elif(actual==0 and predicted==1):
        f_p+=-25.1
        print "fp", f_p
    elif(actual==1 and predicted==0):
        f_n+=-50.0
        print "fn", f_n
    else:
        t_n=0.0
        print "tn", t_n

score=t_p+f_p+f_n+t_n
print score

Now when I pass the following:

0,0
0 0
tn 0.0
0,1
0 1
tn 0.0
1,0
1 0
tn 0.0
1,1
1 1
tn 0.0
1,1
1 1
tn 0.0

It seems to be taking tn value only always which shouldnt be since the values satisfy other conditions based on the values of those two variables.

2 Answers 2

1

line=raw_input() and actual,predicted=line.split(',') will give you actual and predicted in string, which will never equal to int 1. A conversion of the type will fix the problem.

Sign up to request clarification or add additional context in comments.

1 Comment

Aah. I didn't realize. Let me check that
0

Without converting your input data into int, you can keep them like a strings and compare them to your validation data which are tuples like the example below:

t_p = 0
f_p = 0
f_n = 0
t_n = 0

while True:
    data = tuple(raw_input().split(','))

    if data[0] == 'q' or data[0] == '' :
        break
    else:
        print data


    if data == ('1','1'):
        t_p += 50 
        print 'tp', t_p

    if data == ('0','1'):
         f_p -= 25.1
         print 'fp', f_p

    if data == ('1', '0'):
        f_n -= 50.0
        print 'fn', f_n

    else:
        tn = 0.0
        print 'tn', t_n

score = t_n + f_n, + f_p, t_p
print score

Demo:

1,1
('1', '1')
tp 50
tn 0
1,0
('1', '0')
fn -50.0
0,1
('0', '1')
fp -25.1
tn 0
0,0
('0', '0')
tn 0

(-50.0, -25.1, 50)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.