przemowoAnalizator/stats.py

34 lines
899 B
Python

#recall, precision. f1
predictionsFilename = "pred.pred"
testFilename = "test.txt"
actual = []
with open(testFilename, 'r') as tf:
actual = [x.split('|')[0].replace(" ","") for x in tf.readlines()]
predicted=[]
with open(predictionsFilename, 'r') as pf:
predicted=[x.lstrip().rstrip() for x in pf.readlines()]
pairs=zip(actual,predicted)
trueNegative=0
falseNegative=0
falsePositive=0
truePositive=0
for pair in pairs:
if pair[0] == '-1':
if pair[1] == "-1":
trueNegative+=1
else:
falseNegative+=1
elif pair[0] == "+1":
if pair[1] in ["+1", "1"]:
truePositive+=1
else:
falsePositive+=1
precision = truePositive/(truePositive+falsePositive)
recall=truePositive/(truePositive+falseNegative)
f1 = 2*(precision*recall)/(precision+recall)
print(f"Precision: {precision} \n Recall: {recall} \n f1: {f1}")