Package org.tribuo
Class Prediction<T extends Output<T>>
java.lang.Object
org.tribuo.Prediction<T>
- All Implemented Interfaces:
Serializable
,ProtoSerializable<org.tribuo.protos.core.PredictionProto>
public class Prediction<T extends Output<T>>
extends Object
implements ProtoSerializable<org.tribuo.protos.core.PredictionProto>, Serializable
A prediction made by a
Model
.
Contains the output, and optionally and a map of scores over the possible outputs.
If hasProbabilities() == true then it has a probability
distribution over outputs otherwise it is unnormalized scores over outputs.
If possible it also contains the number of features that were used to make a prediction,
and how many features originally existed in the Example
.
- See Also:
-
Field Summary
Modifier and TypeFieldDescriptionstatic final int
The current protobuf serialization version of this class.Fields inherited from interface org.tribuo.protos.ProtoSerializable
DESERIALIZATION_METHOD_NAME, PROVENANCE_SERIALIZER
-
Constructor Summary
ConstructorDescriptionPrediction
(Prediction<T> other, int numUsed, Example<T> example) Constructs a prediction from the supplied arguments.Prediction
(T output, int numUsed, Example<T> example) Constructs a prediction from the supplied arguments.Prediction
(T output, Map<String, T> outputScores, int numUsed, Example<T> example, boolean probability) Constructs a prediction from the supplied arguments. -
Method Summary
Modifier and TypeMethodDescriptionstatic Prediction<?>
deserializeFromProto
(int version, String className, com.google.protobuf.Any message) Deserialization factory.boolean
distributionEquals
(Prediction<T> other) Checks that the other prediction has the same distribution as this prediction, using theOutput.fullEquals(T)
method.boolean
distributionEquals
(Prediction<T> other, double threshold) Checks that the other prediction has the same distribution as this prediction, using theOutput.fullEquals(T)
method.Returns the example itself.int
Returns the number of features in the example.int
Returns the number of features used in the prediction.Returns the predicted output.Gets the output scores for each output.boolean
Are the scores probabilities?org.tribuo.protos.core.PredictionProto
Serializes this object to a protobuf.toString()
-
Field Details
-
CURRENT_VERSION
public static final int CURRENT_VERSIONThe current protobuf serialization version of this class.- See Also:
-
-
Constructor Details
-
Prediction
public Prediction(T output, Map<String, T> outputScores, int numUsed, Example<T> example, boolean probability) Constructs a prediction from the supplied arguments.- Parameters:
output
- The predicted output (i.e., the one with the maximum score).outputScores
- The output score distribution.numUsed
- The number of features used to make the prediction.example
- The input example.probability
- Are the scores probabilities?
-
Prediction
Constructs a prediction from the supplied arguments.- Parameters:
output
- The predicted output.numUsed
- The number of features used to make the prediction.example
- The input example.
-
Prediction
Constructs a prediction from the supplied arguments.- Parameters:
other
- The prediction to copy.numUsed
- The number of features used to make the prediction.example
- The input example.
-
-
Method Details
-
deserializeFromProto
public static Prediction<?> 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
.
-
getOutput
Returns the predicted output.- Returns:
- The predicted output.
-
getNumActiveFeatures
public int getNumActiveFeatures()Returns the number of features used in the prediction.- Returns:
- The number of features used.
-
getExampleSize
public int getExampleSize()Returns the number of features in the example.- Returns:
- The number of features in the example.
-
getExample
Returns the example itself.- Returns:
- The example.
-
getOutputScores
Gets the output scores for each output.May be an empty map if it did not generate scores.
- Returns:
- A Map.
-
hasProbabilities
public boolean hasProbabilities()Are the scores probabilities?- Returns:
- True if the scores are probabilities.
-
toString
-
distributionEquals
Checks that the other prediction has the same distribution as this prediction, using theOutput.fullEquals(T)
method.- Parameters:
other
- The prediction to compare.- Returns:
- True if they have the same distributions.
-
distributionEquals
Checks that the other prediction has the same distribution as this prediction, using theOutput.fullEquals(T)
method.- Parameters:
other
- The prediction to compare.threshold
- The tolerance threshold for the scores.- Returns:
- True if they have the same distributions.
-
serialize
public org.tribuo.protos.core.PredictionProto serialize()Description copied from interface:ProtoSerializable
Serializes this object to a protobuf.- Specified by:
serialize
in interfaceProtoSerializable<T extends Output<T>>
- Returns:
- The protobuf.
-