Record Class ClassificationModel

java.lang.Object
java.lang.Record
smile.model.ClassificationModel
Record Components:
algorithm - the algorithm name.
schema - the schema of input data (without response variable).
formula - the model formula.
classifier - the classification model.
train - the training metrics.
validation - the cross-validation metrics.
test - the test metrics.
tags - the model metadata tags.
All Implemented Interfaces:
Serializable, Model

public record ClassificationModel(String algorithm, StructType schema, Formula formula, DataFrameClassifier classifier, ClassificationMetrics train, ClassificationMetrics validation, ClassificationMetrics test, Properties tags) extends Record implements Model, Serializable
The classification model.
See Also:
  • Constructor Details

  • Method Details

    • predict

      public int predict(Tuple x)
      Model inference.
      Parameters:
      x - the input tuple.
      Returns:
      the prediction.
    • predict

      public int predict(Tuple x, double[] posteriori)
      Model inference.
      Parameters:
      x - the input tuple.
      posteriori - a posteriori probabilities on output.
      Returns:
      the prediction.
    • numClasses

      public int numClasses()
      Returns the number of classes.
      Returns:
      the number of classes.
    • isOnline

      public boolean isOnline()
      Description copied from interface: Model
      Returns true if this model supports online learning updates.
      Specified by:
      isOnline in interface Model
      Returns:
      true if online learning is supported.
    • update

      public void update(Tuple x)
      Description copied from interface: Model
      Online updates the model with a single observation.
      Specified by:
      update in interface Model
      Parameters:
      x - the input tuple (including target variable if supervised).
    • update

      public void update(Tuple x, int y)
      Online updates the classification model with a new training instance.
      Parameters:
      x - the input tuple.
      y - the class label.
    • supportsShap

      public boolean supportsShap()
      Description copied from interface: Model
      Returns true if this model supports SHAP feature explanations.
      Specified by:
      supportsShap in interface Model
      Returns:
      true if SHAP explanations are supported.
    • shap

      public double[][] shap(Tuple x)
      Description copied from interface: Model
      Computes SHAP values for the input tuple.
      Specified by:
      shap in interface Model
      Parameters:
      x - the input tuple.
      Returns:
      the SHAP values (double[] for regression, double[][] for classification).
    • shap

      public double[][] shap(Tuple x, KernelSHAP.Options options)
      Description copied from interface: Model
      Computes SHAP values for the input tuple with custom KernelSHAP.Options.
      Specified by:
      shap in interface Model
      Parameters:
      x - the input tuple.
      options - the KernelSHAP options, or null to use default options.
      Returns:
      the SHAP values (double[] for regression, double[][] for classification).
    • infer

      public Prediction infer(Tuple x, boolean probability, boolean explain)
      Description copied from interface: Model
      Performs inference on a single tuple.
      Specified by:
      infer in interface Model
      Parameters:
      x - the input tuple.
      probability - true to compute posterior probabilities for soft classifiers.
      explain - true to compute feature explanations.
      Returns:
      the prediction.
    • infer

      public Prediction infer(Tuple x, boolean probability, boolean explain, KernelSHAP.Options options)
      Description copied from interface: Model
      Performs inference on a single tuple with custom KernelSHAP.Options.
      Specified by:
      infer in interface Model
      Parameters:
      x - the input tuple.
      probability - true to compute posterior probabilities for soft classifiers.
      explain - true to compute feature explanations.
      options - optional KernelSHAP options (may be null).
      Returns:
      the prediction.
    • infer

      public Prediction[] infer(DataFrame data, boolean probability, boolean explain)
      Description copied from interface: Model
      Performs batch inference over a data frame.
      Specified by:
      infer in interface Model
      Parameters:
      data - the input data frame.
      probability - true to compute posterior probabilities for soft classifiers.
      explain - true to compute feature explanations.
      Returns:
      an array of predictions.
    • infer

      public Prediction[] infer(DataFrame data, boolean probability, boolean explain, KernelSHAP.Options options)
      Description copied from interface: Model
      Performs batch inference over a data frame with custom KernelSHAP.Options.
      Specified by:
      infer in interface Model
      Parameters:
      data - the input data frame.
      probability - true to compute posterior probabilities for soft classifiers.
      explain - true to compute feature explanations.
      options - optional KernelSHAP options (may be null).
      Returns:
      an array of predictions.
    • toString

      public final 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.
    • algorithm

      public String algorithm()
      Returns the value of the algorithm record component.
      Specified by:
      algorithm in interface Model
      Returns:
      the value of the algorithm record component
    • schema

      public StructType schema()
      Returns the value of the schema record component.
      Specified by:
      schema in interface Model
      Returns:
      the value of the schema record component
    • formula

      public Formula formula()
      Returns the value of the formula record component.
      Specified by:
      formula in interface Model
      Returns:
      the value of the formula record component
    • classifier

      public DataFrameClassifier classifier()
      Returns the value of the classifier record component.
      Returns:
      the value of the classifier record component
    • train

      public ClassificationMetrics train()
      Returns the value of the train record component.
      Returns:
      the value of the train record component
    • validation

      public ClassificationMetrics validation()
      Returns the value of the validation record component.
      Returns:
      the value of the validation record component
    • test

      public ClassificationMetrics test()
      Returns the value of the test record component.
      Returns:
      the value of the test record component
    • tags

      public Properties tags()
      Returns the value of the tags record component.
      Specified by:
      tags in interface Model
      Returns:
      the value of the tags record component