Record Class AnomalyModel

java.lang.Object
java.lang.Record
smile.model.AnomalyModel
Record Components:
algorithm - the algorithm name.
schema - the schema of input data (without response variable).
formula - the model formula.
detector - the underlying anomaly detector (IsolationForest, LOF, or SVM).
threshold - the anomaly decision threshold.
transform - optional feature preprocessing transform; may be null.
tags - the model metadata tags.
All Implemented Interfaces:
Serializable, Model

public record AnomalyModel(String algorithm, StructType schema, Formula formula, Serializable detector, double threshold, Transform transform, Properties tags) extends Record implements Model, Serializable
The anomaly detection model.
See Also:
  • Constructor Details

    • AnomalyModel

      public AnomalyModel(String algorithm, StructType schema, Formula formula, Serializable detector, double threshold, Properties tags)
      Constructs an anomaly detection model without a preprocessing transform.
      Parameters:
      algorithm - the algorithm name.
      schema - the schema of input data (without response variable).
      formula - the model formula.
      detector - the underlying anomaly detector.
      threshold - the anomaly decision threshold.
      tags - the model metadata tags.
    • AnomalyModel

      public AnomalyModel(String algorithm, StructType schema, Formula formula, Serializable detector, double threshold, Transform transform, Properties tags)
      Creates an instance of a AnomalyModel record class.
      Parameters:
      algorithm - the value for the algorithm record component
      schema - the value for the schema record component
      formula - the value for the formula record component
      detector - the value for the detector record component
      threshold - the value for the threshold record component
      transform - the value for the transform record component
      tags - the value for the tags record component
  • Method Details

    • score

      public double score(Tuple x)
      Computes the anomaly or decision score for a single observation.
      Parameters:
      x - the input tuple.
      Returns:
      the anomaly or decision score.
    • score

      public double[] score(DataFrame data)
      Computes the anomaly or decision scores for a data frame.
      Parameters:
      data - the input data frame.
      Returns:
      the anomaly or decision scores.
    • predict

      public boolean predict(Tuple x)
      Predicts whether a single observation is an anomaly using the model's threshold.
      Parameters:
      x - the input tuple.
      Returns:
      true if the observation is predicted as an anomaly.
    • predict

      public boolean[] predict(DataFrame data)
      Predicts whether each observation in a data frame is an anomaly.
      Parameters:
      data - the input data frame.
      Returns:
      an array of anomaly flags.
    • 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. Reference components are compared with Objects::equals(Object,Object); primitive components are compared with the compare method from their corresponding wrapper classes.
      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
    • detector

      public Serializable detector()
      Returns the value of the detector record component.
      Returns:
      the value of the detector record component
    • threshold

      public double threshold()
      Returns the value of the threshold record component.
      Returns:
      the value of the threshold record component
    • transform

      public Transform transform()
      Returns the value of the transform record component.
      Returns:
      the value of the transform 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