# F1 score > The **F1 score** is the harmonic mean of precision and recall. The **F1 score** is the [harmonic mean](https://wiki.g15e.com/pages/Harmonic%20mean.txt) of [precision](https://wiki.g15e.com/pages/Precision%20(machine%20learning.txt)) and [recall](https://wiki.g15e.com/pages/Recall%20(machine%20learning.txt)). Mathematically, $$ \text{F1} = 2 \times \frac{\text{precision} \times \text{recall}}{\text{precision} + \text{recall}} $$ which also means: $$ \text{F1} = \frac{2TP}{2TP + FP + FN} $$ ## When (not) to use This metric balances the importance of [precision](https://wiki.g15e.com/pages/Precision%20(machine%20learning.txt)) and [recall](https://wiki.g15e.com/pages/Recall%20(machine%20learning.txt)), and is preferable to accuracy for [class-imbalanced datasets](https://wiki.g15e.com/pages/Class-imbalanced%20dataset.txt). When precision and recall both have perfect scores of 1.0, F1 will also have a perfect score of 1.0. More broadly, when precision and recall are close in value, F1 will be close to their value. When precision and recall are far apart, F1 will be similar to whichever metric is worse.