f score in matlab

To calculate F-score in MATLAB, you can use the f1score function from the Statistics and Machine Learning Toolbox.

Here's an example:

main.m
% True labels
y_true = [0, 1, 0, 1, 1, 1, 0, 1, 0, 0];

% Predicted labels
y_pred = [1, 1, 0, 1, 0, 1, 0, 1, 0, 0];

% Compute F1-score
f1 = f1score(y_true, y_pred)

% Display result
fprintf('F1-score: %.2f\n', f1);
216 chars
12 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