f1Score function

double f1Score(
  1. List<int> yTrue,
  2. List<int> yPred, {
  3. int positiveLabel = 1,
})

F1 Score is the harmonic mean of precision and recall.

Implementation

double f1Score(List<int> yTrue, List<int> yPred, {int positiveLabel = 1}) {
  final p = precision(yTrue, yPred, positiveLabel: positiveLabel);
  final r = recall(yTrue, yPred, positiveLabel: positiveLabel);

  final denominator = p + r;
  return denominator == 0 ? 0.0 : 2 * p * r / denominator;
}