To calculate F-score in MATLAB, you can use the f1score
function from the Statistics and Machine Learning Toolbox.
Here's an example:
main.m216 chars12 lines
In this example, y_true
contains the true labels and y_pred
contains the predicted labels. The f1score
function calculates the F1-score and returns it as f1
.
The F1-score is a harmonic mean of precision and recall, where precision is the ratio of true positive predictions to all positive predictions, and recall is the ratio of true positive predictions to all actual positive instances.
Note that f1score
function can also take in optional name-value pair arguments, such as 'Beta'
for calculating Fβ-score and 'Class'
for multiclass problems.
gistlibby LogSnag