I am using fastText with Python, which gives precision and recall, but not accuracy. How do I get accuracy from fastText? Or, alternatively, how do I calculate accuracy given precision and recall?
Asked
Active
Viewed 1,074 times
-1
-
Are these not items you can look up on line? Where are you stuck? Also, just to check, which definition of "accuracy" are you using? We don't generally include true negatives for text applications. – Prune Jul 23 '19 at 17:52
-
I am using fastText for 3-class 1-label text classification. I'd like to get accuracy score on a validation set. – Software Dev Jul 23 '19 at 17:58
-
[fastText sentiment](https://medium.com/@media_73863/fasttext-sentiment-analysis-for-tweets-a-straightforward-guide-9a8c070449a2) from this article it seems like you get the accuracy by looking at the second position of the model.test(..)[1] might wanna try that. Also there is no way to compute the "accuracy" from precision and recall since they both don't have True Negatives. – Manvir Jul 23 '19 at 18:16
-
model.test(...) returns precision and recall. The tutorial is misleading. – Software Dev Jul 23 '19 at 20:58
1 Answers
0
I did this code, taking data from a row in a CSV (starting with the label) and comparing with the prediction, then it saves in a .txt
f = open('accuracy.txt', 'w')
total, correct = 0, 0
for idx, row in X.iteritems():
#Getting data from a CSV
line = row.split()
label = line[0]
description = " ".join(line[1:])
#Predicting
predict = model.predict(description , k=1)
#Saving accuracy
total += 1
if(predict[0][0] == label):
correct += 1
f.writelines("Accuracy = " + str(correct/total) + '\n')
f.close()

Rodrigo Leão
- 16
- 1