Class F1Score

java.lang.Object
smile.deep.metric.F1Score
All Implemented Interfaces:
Metric

public class F1Score extends Object implements Metric
F1 score is the harmonic mean of precision and recall:
    F1 = 2 * (precision * recall) / (precision + recall)
       = 2 * TP / (2 * TP + FP + FN)
It reaches its best value at 1 (perfect precision and recall) and its worst value at 0.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Constructor for binary classification.
    F1Score(double threshold)
    Constructor for binary classification with a custom threshold.
    F1Score(Averaging strategy)
    Constructor for multi-class classification.
  • Method Summary

    Modifier and Type
    Method
    Description
    double
    Computes the metric value from the metric state, which are updated by previous update() calls.
    Returns the name of metric.
    void
    Resets the metric state variables to their default value.
     
    void
    update(Tensor output, Tensor target)
    Updates the metric states with input data.

    Methods inherited from class Object

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

    • F1Score

      public F1Score()
      Constructor for binary classification.
    • F1Score

      public F1Score(double threshold)
      Constructor for binary classification with a custom threshold.
      Parameters:
      threshold - the threshold for converting model output to binary label.
    • F1Score

      public F1Score(Averaging strategy)
      Constructor for multi-class classification.
      Parameters:
      strategy - the averaging strategy (Macro, Micro, or Weighted).
  • Method Details

    • name

      public String name()
      Description copied from interface: Metric
      Returns the name of metric.
      Specified by:
      name in interface Metric
      Returns:
      the name of metric.
    • toString

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

      public void update(Tensor output, Tensor target)
      Description copied from interface: Metric
      Updates the metric states with input data. This is often used when new data needs to be added for metric computation.
      Specified by:
      update in interface Metric
      Parameters:
      output - the model output.
      target - the ground truth.
    • compute

      public double compute()
      Description copied from interface: Metric
      Computes the metric value from the metric state, which are updated by previous update() calls. The compute frequency can be less than the update frequency.
      Specified by:
      compute in interface Metric
      Returns:
      the metric value.
    • reset

      public void reset()
      Description copied from interface: Metric
      Resets the metric state variables to their default value. Usually this is called at the end of every epoch to clean up metric states.
      Specified by:
      reset in interface Metric