MLmediumEvaluation~10m
F1 Score Implementation
Problem
Implement the F1 score metric using only NumPy. The F1 score is the harmonic mean of precision and recall: F1 = 2 * (precision * recall) / (precision + recall), where precision = TP/(TP+FP) and recall = TP/(TP+FN).
Examples
Example 1
Input:
y_true=[1, 0, 1, 1, 0], y_pred=[1, 0, 1, 0, 0]Output:
0.8TP=2, FP=0, FN=1 gives precision=1.0, recall=0.667, F1=0.8 / 1.2 = 0.66667
Constraints
- ›NumPy only (import numpy as np)
- ›Function must be named solution
Reference solution
Reference solution available after you attempt the question.
Ready to solve it?
Start a session on Mockbit #93. You'll get graded with specific critique when you submit.
Related ML questions
← Back homemockbit.io/q/93