Record Class Prediction

java.lang.Object
java.lang.Record
smile.model.Prediction
Record Components:
output - the predicted value (class label, cluster label, prototype index/grid cell, anomaly flag, or regression output).
probabilities - posteriori class probabilities for soft classifiers; null for hard classifiers, regressors, clustering, vector quantization, and anomaly detection models.
centroid - cluster centroid or prototype code vector coordinates; null for classifiers, regressors, and anomaly detection models.
error - quantization error (distance to prototype) for vector quantization models; null otherwise.
score - anomaly or decision score for anomaly detection models; null otherwise.
explanations - the prediction explanations; null if not requested.
All Implemented Interfaces:
Serializable

public record Prediction(Object output, double[] probabilities, double[] centroid, Double error, Double score, Explanations explanations) extends Record implements Serializable
The model prediction containing the predicted output value, optional class probability estimates for soft classification models, optional cluster/prototype centroid coordinates for clustering and vector quantization models, optional quantization error, optional anomaly score, and optional explanations.
See Also:
  • Constructor Details

    • Prediction

      public Prediction(Number output)
      Constructs a prediction without probability estimates or explanations.
      Parameters:
      output - the predicted value.
    • Prediction

      public Prediction(Number output, double[] probabilities)
      Constructs a prediction with optional probability estimates and no explanations.
      Parameters:
      output - the predicted value.
      probabilities - posteriori class probabilities.
    • Prediction

      public Prediction(Number output, double[] probabilities, Explanations explanations)
      Constructs a prediction with optional probability estimates and explanations.
      Parameters:
      output - the predicted value.
      probabilities - posteriori class probabilities.
      explanations - the prediction explanations.
    • Prediction

      public Prediction(Number output, double[] probabilities, double[] centroid, Explanations explanations)
      Constructs a prediction with optional probability estimates, centroid, and explanations.
      Parameters:
      output - the predicted value.
      probabilities - posteriori class probabilities.
      centroid - cluster centroid coordinates.
      explanations - the prediction explanations.
    • Prediction

      public Prediction(Object output, double[] probabilities, double[] centroid, Double error, Explanations explanations)
      Constructs a prediction with optional probability estimates, centroid, error, and explanations.
      Parameters:
      output - the predicted value.
      probabilities - posteriori class probabilities.
      centroid - cluster or prototype centroid coordinates.
      error - quantization error.
      explanations - the prediction explanations.
    • Prediction

      public Prediction(Boolean anomaly, Double score, Explanations explanations)
      Constructs an anomaly detection prediction with anomaly flag, score, and optional explanations.
      Parameters:
      anomaly - the anomaly flag (true for anomaly, false for normal).
      score - the anomaly or decision score.
      explanations - the prediction explanations.
    • Prediction

      public Prediction(Object output, double[] probabilities, double[] centroid, Double error, Double score, Explanations explanations)
      Creates an instance of a Prediction record class.
      Parameters:
      output - the value for the output record component
      probabilities - the value for the probabilities record component
      centroid - the value for the centroid record component
      error - the value for the error record component
      score - the value for the score record component
      explanations - the value for the explanations record component
  • Method Details

    • toJson

      public String toJson()
      Serializes this prediction to a JSON string.
      Returns:
      the JSON string representation.
    • toString

      public String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared with Objects::equals(Object,Object).
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • output

      public Object output()
      Returns the value of the output record component.
      Returns:
      the value of the output record component
    • probabilities

      public double[] probabilities()
      Returns the value of the probabilities record component.
      Returns:
      the value of the probabilities record component
    • centroid

      public double[] centroid()
      Returns the value of the centroid record component.
      Returns:
      the value of the centroid record component
    • error

      public Double error()
      Returns the value of the error record component.
      Returns:
      the value of the error record component
    • score

      public Double score()
      Returns the value of the score record component.
      Returns:
      the value of the score record component
    • explanations

      public Explanations explanations()
      Returns the value of the explanations record component.
      Returns:
      the value of the explanations record component