0

I have this code:

TP = len(set1)
FP = len(set2)
FN = len(set3)

if FP == 0:
    Score = ((2*TP)/((2*TP)+FN))
    print "Warning: FP is equal 0."

elif FN == 0:
     Score = ((2*TP)/((2*TP)+FP))
     print "Warning: FN is equal 0"

elif TP == 0:
    Score = ((2*TP)/((2*TP)+FP+FN))
    print "Warning: TP is equal 0"

else:
    Score = ((2*TP)/((2*TP)+FP+FN))

print " The Score is = ", Score

But for some reason my Score returns 0 every time. I checked the values and everything seems correct. Anyone could help me??

mdpoleto
  • 711
  • 2
  • 6
  • 10

1 Answers1

1

Because you are using integer division every time. Instead of 2 constant use 2.0 to force python's division return a float.

Ex:

Score = ((2.0*TP)/((2.0*TP)+FN))

As a side note you can read more on forcing a floating division in this question: How can I force division to be floating point? Division keeps rounding down to 0 and in the docs: Decimals, Floats, and Floating Point Arithmetic

Community
  • 1
  • 1
Paulo Bu
  • 29,294
  • 6
  • 74
  • 73