6

Duplicate calculating Precision, Recall and F Score

I have a input file with text description and classified level (i.e.levelA and levelB). I want to write a SVM classifier that measure precision, recall and accuracy. I looked at scikit and LIBSVM but I want to know more step by step.

Any sample code or basic tutorial would be really nice. Thanks for any suggestion in advance.

Community
  • 1
  • 1
  • possible duplicate of [How to calculate precision, recall and F-score with libSVM in python](http://stackoverflow.com/questions/16927964/how-to-calculate-precision-recall-and-f-score-with-libsvm-in-python) – jabaldonedo Jul 11 '13 at 13:18
  • 1
    Here's an extension for `libsvm`: http://www.csie.ntu.edu.tw/~cjlin/libsvmtools/eval/index.html – Mihai Todor Jul 11 '13 at 14:44

1 Answers1

10

These performance measures are easy to obtain from the predicted labels and true labels, as a post-processing step:

  1. Precision = TP / (TP+FP)
  2. Recall = TP / (TP+FN)
  3. Accuracy = (TP + TN) / (TP + TN + FP + FN)

With TP, FP, TN, FN being number of true positives, false positives, true negatives and false negatives, respectively.

Marc Claesen
  • 16,778
  • 6
  • 27
  • 62
  • Thanks Marc, but I already did some study some basics but I need more specific information step by step implementation process. –  Jul 11 '13 at 11:06
  • 4
    The steps are: train an SVM (make sure to tune it properly), predict the test set, compute performance measures based on predicted labels and true labels. – Marc Claesen Jul 11 '13 at 11:14
  • Can you please suggest me any tutorial or book with code snippets. I don't want exact whole code but for learning purpose it would be really useful. Thanks. –  Jul 11 '13 at 11:25
  • 2
    @Raid The code is trivial. It is just a matter of keeping four counters and then using the formulae that Marc provided. For each predicted label: if predicted label == true label and true label is positive, increment TP; if predicted label == true label and label is negative, increment TN; if predicted label is positive and true label is negative; increment FP; otherwise increment FN. Try this video: http://www.youtube.com/watch?v=2akd6uwtowc. – Bull Jul 11 '13 at 13:00