Class Label

java.lang.Object
org.tribuo.classification.Label
All Implemented Interfaces:
Serializable, Classifiable<Label>, Output<Label>

public final class Label extends Object implements Classifiable<Label>
An immutable multi-class classification label.

The labels themselves are Strings. A Label also contains an optional score which measures the confidence in that label, though it is not required to be a probability.

Label equality and hashCode is defined solely on the String label, it does not take into account the score.

See Also:
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected final String
    The name of the label.
    protected final double
    The score of the label.
    static final String
    The name of the unknown label (i.e., an unlabelled output).
  • Constructor Summary

    Constructors
    Constructor
    Description
    Label(String label)
    Builds a label with the sentinel score of Double.NaN.
    Label(String label, double score)
    Builds a label with the supplied string and score.
  • Method Summary

    Modifier and Type
    Method
    Description
    Deep copy of the output up to it's immutable state.
    boolean
     
    boolean
    Compares other to this output.
    Gets the name of this label.
    double
    Get a real valued score for this label.
    getSerializableForm(boolean includeConfidence)
    Returns "labelName" or "labelName,score=labelScore".
    int
     
     

    Methods inherited from class java.lang.Object

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

    • UNKNOWN

      public static final String UNKNOWN
      The name of the unknown label (i.e., an unlabelled output).
      See Also:
    • label

      protected final String label
      The name of the label.
    • score

      protected final double score
      The score of the label.
  • Constructor Details

    • Label

      public Label(String label, double score)
      Builds a label with the supplied string and score.
      Parameters:
      label - The label name.
      score - The label instance score.
    • Label

      public Label(String label)
      Builds a label with the sentinel score of Double.NaN.
      Parameters:
      label - The name of this label.
  • Method Details

    • getScore

      public double getScore()
      Get a real valued score for this label.

      If the score is not set then it returns Double.NaN.

      Returns:
      The predicted score for this label.
    • getLabel

      public String getLabel()
      Gets the name of this label.
      Returns:
      A String.
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • fullEquals

      public boolean fullEquals(Label o)
      Description copied from interface: Output
      Compares other to this output. Uses all score values and the strings.
      Specified by:
      fullEquals in interface Output<Label>
      Parameters:
      o - Another output instance.
      Returns:
      True if the other instance has value equality to this instance. False otherwise.
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

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

      public Label copy()
      Description copied from interface: Output
      Deep copy of the output up to it's immutable state.
      Specified by:
      copy in interface Output<Label>
      Returns:
      A copy of the output.
    • getSerializableForm

      public String getSerializableForm(boolean includeConfidence)
      Returns "labelName" or "labelName,score=labelScore".
      Specified by:
      getSerializableForm in interface Output<Label>
      Parameters:
      includeConfidence - Include whatever confidence score the label contains, if known.
      Returns:
      A String form suitable for serialization.