Class FScore

java.lang.Object
smile.validation.metric.FScore
All Implemented Interfaces:
Serializable, 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)
    Constructor of general F-score.
  • Method Summary

    Modifier and Type
    Method
    Description
    static double
    of(double beta, int[] truth, int[] prediction)
    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
  • 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)
      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.
  • 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.
    • of

      public static double of(double beta, int[] truth, int[] prediction)
      Calculates the F1 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.
      truth - the ground truth.
      prediction - the prediction.
      Returns:
      the metric.
    • toString

      public String toString()
      Overrides:
      toString in class Object