简体   繁体   中英

fastText with Python: Calculate Accuracy

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?

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()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM