Search code examples
scikit-learnsvmprecision-recall

Calculating accuracy from precision, recall, f1-score - scikit-learn


I made a huge mistake. I printed output of scikit-learn svm accuracy as:

str(metrics.classification_report(trainExpected, trainPredict, digits=6))

Now I need to calculate accuracy from following output:

              precision    recall  f1-score   support

1             0.000000  0.000000  0.000000      1259
2             0.500397  1.000000  0.667019      1261
avg / total   0.250397  0.500397  0.333774      2520

Is it possible to calculate accuracy from these values?

PS: I don't want to spend another day for getting outputs of the model. I just realized this mistake hopefully I don't need to start from the beginning.


Solution

  • No need to spend more time on it. The metrics module has everything you need in it and you have already computed the predicted values. It's a one line change.

    print(metrics.accuracy_score(trainExpected, trainPredict))
    

    I suggest that you spend some time to read the linked page to learn more about evaluating models in general.

    I do think you have a bigger problem with at hand -- you have zero predicted values for your 1 class, despite having balanced classes. You likely have a problem in your data, modeling strategy, or code that you'll have to deal with.