F1 Score

MediumMachine LearningArray

Description

Given equal-length binary arrays yTrue and yPred (1 = positive), return the F1 score (harmonic mean of precision and recall), rounded to 4 decimal places. If precision + recall is 0, return 0.

Examples

Input:yTrue = [1,0,1,1], yPred = [1,1,1,0]
Output:0.6667
Explanation:

Combining precision and recall through their harmonic mean gives 0.6667.

Input:yTrue = [1,1,0,0], yPred = [1,0,0,0]
Output:0.6667
Explanation:

Combining precision and recall through their harmonic mean gives 0.6667.

Input:yTrue = [0,0], yPred = [0,0]
Output:0
Explanation:

Combining precision and recall through their harmonic mean gives 0.

Constraints

  • 1 ≤ yTrue.length ≤ 10⁴
  • values are 0 or 1

Ready to solve this problem?

Practice solo and sharpen your skills for technical interviews.