pythonprecision-recallfasttextperformance-measuring

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?


Solution

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