Class MultiLabel
java.lang.Object
org.tribuo.multilabel.MultiLabel
- All Implemented Interfaces:
Serializable,Classifiable<MultiLabel>,Output<MultiLabel>
A class for multi-label classification.
Multi-label classification is where a (possibly empty) set of labels is predicted for each example. For example, predicting that a Reuters article has both the Finance and Sports labels.
- See Also:
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionMultiLabel(String label) Builds a MultiLabel with a single String label.MultiLabel(Set<Label> labels) Builds a MultiLabel object from a Set of Labels.MultiLabel(Set<Label> labels, double score) Builds a MultiLabel object from a Set of Labels, when the whole set has a score as well as (optionally) the individual labels.MultiLabel(Label label) Builds a MultiLabel from a single Label. -
Method Summary
Modifier and TypeMethodDescriptionbooleanDoes this MultiLabel contain this string?booleanDoes this MultiLabel contain this Label?copy()Deep copy of the output up to it's immutable state.static MultiLabelcreateFromPairList(List<com.oracle.labs.mlrg.olcut.util.Pair<String, Boolean>> dimensions) Creates a MultiLabel from a list of dimensions.createLabel(Label otherLabel) Creates a binary label from this multilabel.booleanbooleanCompares other to this output.The set of labels contained in this multilabel.Returns a comma separated string representing the labels in this multilabel instance.The set of strings that represent the labels in this multilabel.doublegetScore()The overall score for this set of labels.getSerializableForm(boolean includeConfidence) For a MultiLabel with label set = {a, b, c}, outputs a string of the form:inthashCode()Parses a string of the form:static MultiLabelParses a string of the form: dimension-name=output,...,dimension-name=output where output must be readable byBoolean.parseBoolean(String).static MultiLabelparseString(String s, char splitChar) Parses a string of the form:toString()
-
Field Details
-
NEGATIVE_LABEL_STRING
- See Also:
-
NEGATIVE_LABEL
A Label representing the binary negative label. Used in binary approaches to multi-label classification to represent the absence of a Label.
-
-
Constructor Details
-
MultiLabel
Builds a MultiLabel object from a Set of Labels. Sets the whole set score toDouble.NaN.- Parameters:
labels- A set of (possibly scored) labels.
-
MultiLabel
Builds a MultiLabel object from a Set of Labels, when the whole set has a score as well as (optionally) the individual labels.- Parameters:
labels- A set of (possibly scored) labels.score- An overall score for the set.
-
MultiLabel
Builds a MultiLabel with a single String label. The createdLabelis unscored and used by MultiLabelInfo. Sets the whole set score toDouble.NaN.- Parameters:
label- The label.
-
MultiLabel
Builds a MultiLabel from a single Label. Sets the whole set score toDouble.NaN.- Parameters:
label- The label.
-
-
Method Details
-
createLabel
Creates a binary label from this multilabel. The returned Label is the input parameter if this MultiLabel contains that Label, andNEGATIVE_LABELotherwise.- Parameters:
otherLabel- The input label.- Returns:
- A binarised form of this MultiLabel.
-
getLabelString
Returns a comma separated string representing the labels in this multilabel instance.- Returns:
- A comma separated string of labels.
-
getScore
The overall score for this set of labels.- Returns:
- The score for this MultiLabel.
-
getLabelSet
The set of labels contained in this multilabel.- Returns:
- The set of labels.
-
getNameSet
The set of strings that represent the labels in this multilabel.- Returns:
- The set of strings.
-
contains
-
contains
-
equals
-
fullEquals
Description copied from interface:OutputCompares other to this output. Uses all score values and the strings.- Specified by:
fullEqualsin interfaceOutput<MultiLabel>- Parameters:
o- Another output instance.- Returns:
- True if the other instance has value equality to this instance. False otherwise.
-
hashCode
-
toString
-
copy
Description copied from interface:OutputDeep copy of the output up to it's immutable state.- Specified by:
copyin interfaceOutput<MultiLabel>- Returns:
- A copy of the output.
-
getSerializableForm
For a MultiLabel with label set = {a, b, c}, outputs a string of the form:"a=true,b=true,c=true"
If includeConfidence is set to true, outputs a string of the form:"a=true,b=true,c=true:0.5"
where the last element after the colon is this label's score.- Specified by:
getSerializableFormin interfaceOutput<MultiLabel>- Parameters:
includeConfidence- Include whatever confidence score the label contains, if known.- Returns:
- a comma-separated, densified string representation of this MultiLabel
-
parseString
Parses a string of the form: dimension-name=output,...,dimension-name=output where output must be readable byBoolean.parseBoolean(String).- Parameters:
s- The string form of a multi-label example.- Returns:
- A
MultiLabelparsed from the input string.
-
parseString
Parses a string of the form:dimension-name=output<splitChar>...<splitChar>dimension-name=output
where output must be readable byBoolean.parseBoolean(java.lang.String).- Parameters:
s- The string form of a multilabel output.splitChar- The char to split on.- Returns:
- A
MultiLabeloutput parsed from the input string.
-
parseElement
Parses a string of the form:class1=trueOR of the form:class1In the first case, the value in the "key=value" pair must be parseable byBoolean.parseBoolean(String). TODO: Boolean.parseBoolean("1") returns false. We may want to think more carefully about this case.- Parameters:
s- The string form of a single dimension from a multilabel input.- Returns:
- A tuple representing the dimension name and the value.
-
createFromPairList
public static MultiLabel createFromPairList(List<com.oracle.labs.mlrg.olcut.util.Pair<String, Boolean>> dimensions) Creates a MultiLabel from a list of dimensions.- Parameters:
dimensions- The dimensions to use.- Returns:
- A MultiLabel representing these dimensions.
-