Search code examples
multiclass-classificationfasttext

How to get f1 score in fasttext


I am following the tutorial:

https://fasttext.cc/docs/en/supervised-tutorial.html#our-first-classifier

I have a multiclass data with 26 labels. What does P@1 and R@1 means ?

If I have to get F1-score correspondingly, how can I get it ?


Solution

  • P@1 and R@1 are respectively precision and recall when the model is called to predict the single most likely class.

    In some contexts (web information retrieval, recommender systems), it makes more sense that the model predicts k multiple classes and therefore we are interested in evaluating P@k and R@k.

    In the case in question (prediction of a class among 26), you can compute micro F1-score by inserting the values ​​of P@1 and R@1 in formula:

    F1 = 2 * (precision * recall) / (precision + recall)
    

    To understand the differences between micro F1, macro F1... read scikit-learn docs.

    In any case, if your goal is to train a model that maximizes the value of F1, you can let fastText handle the training through Automatic hyperparameter optimization.