Class Label
java.lang.Object
org.tribuo.classification.Label
- All Implemented Interfaces:
Serializable,Classifiable<Label>,Output<Label>,ProtoSerializable<org.tribuo.protos.core.OutputProto>
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
FieldsModifier and TypeFieldDescriptionprotected final StringThe name of the label.protected final doubleThe score of the label.static final StringThe name of the unknown label (i.e., an unlabelled output).Fields inherited from interface org.tribuo.protos.ProtoSerializable
DESERIALIZATION_METHOD_NAME, PROVENANCE_SERIALIZER -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptioncopy()Deep copy of the output up to its immutable state.static LabeldeserializeFromProto(int version, String className, com.google.protobuf.Any message) Deserialization factory.booleanbooleanfullEquals(Label o) Compares other to this output.booleanfullEquals(Label o, double tolerance) Compares other to this output.getLabel()Gets the name of this label.doublegetScore()Get a real valued score for this label.getSerializableForm(boolean includeConfidence) Returns "labelName" or "labelName,score=labelScore".inthashCode()org.tribuo.protos.core.OutputProtoSerializes this object to a protobuf.toString()
-
Field Details
-
UNKNOWN
The name of the unknown label (i.e., an unlabelled output).- See Also:
-
label
The name of the label. -
score
protected final double scoreThe score of the label.
-
-
Constructor Details
-
Label
Builds a label with the supplied string and score.- Parameters:
label- The label name.score- The label instance score.
-
Label
Builds a label with the sentinel score of Double.NaN.- Parameters:
label- The name of this label.
-
-
Method Details
-
deserializeFromProto
public static Label deserializeFromProto(int version, String className, com.google.protobuf.Any message) throws com.google.protobuf.InvalidProtocolBufferException Deserialization factory.- Parameters:
version- The serialized object version.className- The class name.message- The serialized data.- Returns:
- The deserialized object.
- Throws:
com.google.protobuf.InvalidProtocolBufferException- If the protobuf could not be parsed from themessage.
-
serialize
public org.tribuo.protos.core.OutputProto serialize()Description copied from interface:ProtoSerializableSerializes this object to a protobuf.- Specified by:
serializein interfaceProtoSerializable<org.tribuo.protos.core.OutputProto>- Returns:
- The protobuf.
-
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
-
equals
-
fullEquals
Description copied from interface:OutputCompares other to this output. Uses all score values and the strings.- Specified by:
fullEqualsin interfaceOutput<Label>- Parameters:
o- Another output instance.- Returns:
- True if the other instance has value equality to this instance. False otherwise.
-
fullEquals
Description copied from interface:OutputCompares other to this output. Uses all score values and the strings.The default implementation of this method ignores the tolerance for compatibility reasons, it is overridden in all output classes in Tribuo.
- Specified by:
fullEqualsin interfaceOutput<Label>- Parameters:
o- Another output instance.tolerance- The tolerance level for an absolute value comparison.- Returns:
- True if the other instance has value equality to this instance. False otherwise.
-
hashCode
-
toString
-
copy
-
getSerializableForm
Returns "labelName" or "labelName,score=labelScore".- Specified by:
getSerializableFormin interfaceOutput<Label>- Parameters:
includeConfidence- Include whatever confidence score the label contains, if known.- Returns:
- A String form suitable for serialization.
-