Class FScore

java.lang.Object
smile.validation.metric.FScore
All Implemented Interfaces:
Serializable, ToDoubleBiFunction<int[],int[]>, ClassificationMetric

public class FScore extends Object implements ClassificationMetric
The F-score (or F-measure) considers both the precision and the recall of the test to compute the score. The precision p is the number of correct positive results divided by the number of all positive results, and the recall r is the number of correct positive results divided by the number of positive results that should have been returned.

The traditional or balanced F-score (F1 score) is the harmonic mean of precision and recall, where an F1 score reaches its best value at 1 and worst at 0.

The general formula involves a positive real β so that F-score measures the effectiveness of retrieval with respect to a user who attaches β times as much importance to recall as precision.

See Also:
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final FScore
    The F_1 score, the harmonic mean of precision and recall.
    static final FScore
    The F_2 score, which weighs recall higher than precision.
    static final FScore
    The F_0.5 score, which weighs recall lower than precision.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Constructor of F1 score.
    FScore(double beta, Averaging strategy)
    Constructor of general F-score.
  • Method Summary

    Modifier and Type
    Method
    Description
    static double
    of(int[] truth, int[] prediction, double beta, Averaging strategy)
    Calculates the F1 score.
    double
    score(int[] truth, int[] prediction)
    Returns a score to measure the quality of classification.
     

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait

    Methods inherited from interface smile.validation.metric.ClassificationMetric

    applyAsDouble
  • Field Details

    • F1

      public static final FScore F1
      The F_1 score, the harmonic mean of precision and recall.
    • F2

      public static final FScore F2
      The F_2 score, which weighs recall higher than precision.
    • FHalf

      public static final FScore FHalf
      The F_0.5 score, which weighs recall lower than precision.
  • Constructor Details

    • FScore

      public FScore()
      Constructor of F1 score.
    • FScore

      public FScore(double beta, Averaging strategy)
      Constructor of general F-score.
      Parameters:
      beta - a positive value such that F-score measures the effectiveness of retrieval with respect to a user who attaches β times as much importance to recall as precision.
      strategy - The aggregating strategy for multi-classes.
  • Method Details

    • score

      public double score(int[] truth, int[] prediction)
      Description copied from interface: ClassificationMetric
      Returns a score to measure the quality of classification.
      Specified by:
      score in interface ClassificationMetric
      Parameters:
      truth - the true class labels.
      prediction - the predicted class labels.
      Returns:
      the metric.
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • of

      public static double of(int[] truth, int[] prediction, double beta, Averaging strategy)
      Calculates the F1 score.
      Parameters:
      truth - the ground truth.
      prediction - the prediction.
      beta - a positive value such that F-score measures the effectiveness of retrieval with respect to a user who attaches β times as much importance to recall as precision.
      Returns:
      the metric.