Class FMeasure

java.lang.Object
opennlp.tools.util.eval.FMeasure

public final class FMeasure extends Object
The FMeasure is a utility class for evaluators which measures precision, recall and the resulting f-measure.

Evaluation results are the arithmetic mean of the precision scores calculated for each reference sample and the arithmetic mean of the recall scores calculated for each reference sample.

  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private long
    |selected| = true positives + false positives
    the count of selected (or retrieved) items.
    private long
    |target| = true positives + false negatives
    the count of target (or correct) items.
    private long
    Holds the number of true positives found.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    (package private) static int
    countTruePositives(Object[] references, Object[] predictions)
    This method counts the number of objects which are equal and occur in the references and predictions arrays.
    double
    f-measure = 2 * precision * recall / (precision + recall).
    double
     
    double
     
    void
    Merge results into metric.
    static double
    precision(Object[] references, Object[] predictions)
    Calculates the precision score for the given reference and predicted spans.
    static double
    recall(Object[] references, Object[] predictions)
    Calculates the recall score for the given reference and predicted spans.
     
    void
    updateScores(Object[] references, Object[] predictions)
    Updates the score based on the number of true positives and the number of predictions and references.

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Field Details

    • selected

      private long selected
      |selected| = true positives + false positives
      the count of selected (or retrieved) items.
    • target

      private long target
      |target| = true positives + false negatives
      the count of target (or correct) items.
    • truePositive

      private long truePositive
      Holds the number of true positives found.
  • Constructor Details

    • FMeasure

      public FMeasure()
  • Method Details

    • getPrecisionScore

      public double getPrecisionScore()
      Returns:
      Retrieves the arithmetic mean of the precision scores calculated for each evaluated sample.
    • getRecallScore

      public double getRecallScore()
      Returns:
      Retrieves the arithmetic mean of the recall score calculated for each evaluated sample.
    • getFMeasure

      public double getFMeasure()
      f-measure = 2 * precision * recall / (precision + recall).
      Returns:
      Retrieves the f-measure or -1 if precision + recall <= 0
    • updateScores

      public void updateScores(Object[] references, Object[] predictions)
      Updates the score based on the number of true positives and the number of predictions and references.
      Parameters:
      references - the provided references
      predictions - the predicted spans
    • mergeInto

      public void mergeInto(FMeasure measure)
      Merge results into metric.
      Parameters:
      measure - The FMeasure to merge.
    • toString

      public String toString()
      Overrides:
      toString in class Object
      Returns:
      A human-readable String representation.
    • countTruePositives

      static int countTruePositives(Object[] references, Object[] predictions)
      This method counts the number of objects which are equal and occur in the references and predictions arrays. Matched items are removed from the prediction list.
      Parameters:
      references - The gold standard.
      predictions - The predictions.
      Returns:
      The number of true positives.
    • precision

      public static double precision(Object[] references, Object[] predictions)
      Calculates the precision score for the given reference and predicted spans.
      Parameters:
      references - The gold standard spans.
      predictions - The predicted spans.
      Returns:
      The precision score or NaN if there are no predicted spans.
    • recall

      public static double recall(Object[] references, Object[] predictions)
      Calculates the recall score for the given reference and predicted spans.
      Parameters:
      references - The gold standard spans
      predictions - The predicted spans
      Returns:
      The recall score or NaN if there are no reference spans.