-1

So I am having a really weird issue here. I am not new to python but this type of scenario I haven't faced before. In my own k-nearest algo I have 2 variables i.e. correct and total. The value of correct varies from 133 to 136 and that of total is fixed i.e. 199, but when I print their division it gives me 0. Here is what I am doing:-

print(correct)    #prints 133-136
print(total)      # prints 139
print("Accuracy: ",correct/total)   #prints 0   # have tried // also

Since, I am dealing with accuracy and precision here so I need the result to be 0.95 to 0.97 and not 0, please help me fix this situation. I am using python 2 and have tried print("Accuracy: ",float(correct/total)) which didn't work either.

Asim
  • 1,430
  • 1
  • 22
  • 43

1 Answers1

3

I guess you're using python 2. Try this:

float(correct)/total
Pablo Santa Cruz
  • 176,835
  • 32
  • 241
  • 292