Interface Model

All Known Implementing Classes:
AnomalyModel, ClassificationModel, ClusteringModel, RegressionModel, VectorQuantizerModel

public interface Model
Generic model interface.
  • Field Details

  • Method Details

    • algorithm

      String algorithm()
      Returns the algorithm name.
      Returns:
      the algorithm name.
    • schema

      StructType schema()
      Returns the schema of input data (without response variable).
      Returns:
      the schema of input data (without response variable).
    • formula

      Formula formula()
      Returns the model formula.
      Returns:
      the model formula.
    • tags

      Properties tags()
      Returns the model metadata tags.
      Returns:
      the model metadata tags.
    • getTag

      default String getTag(String key)
      Returns the model metadata tag.
      Parameters:
      key - the tag key.
      Returns:
      the tag value.
    • getTag

      default String getTag(String key, String defaultValue)
      Returns the model metadata tag.
      Parameters:
      key - the tag key.
      defaultValue - a default value.
      Returns:
      the tag value.
    • setTag

      default void setTag(String key, String value)
      Sets a model metadata tag.
      Parameters:
      key - the tag key.
      value - the tag value.
    • isOnline

      default boolean isOnline()
      Returns true if this model supports online learning updates.
      Returns:
      true if online learning is supported.
    • update

      default void update(Tuple x)
      Online updates the model with a single observation.
      Parameters:
      x - the input tuple (including target variable if supervised).
      Throws:
      UnsupportedOperationException - if online learning is not supported.
    • update

      default void update(DataFrame data)
      Online updates the model sequentially with a data frame of observations.
      Parameters:
      data - the input data frame.
      Throws:
      UnsupportedOperationException - if online learning is not supported.
    • supportsShap

      default boolean supportsShap()
      Returns true if this model supports SHAP feature explanations.
      Returns:
      true if SHAP explanations are supported.
    • shap

      default Object shap(Tuple x)
      Computes SHAP values for the input tuple.
      Parameters:
      x - the input tuple.
      Returns:
      the SHAP values (double[] for regression, double[][] for classification).
      Throws:
      UnsupportedOperationException - if SHAP explanations are not supported.
    • shap

      default Object shap(Tuple x, KernelSHAP.Options options)
      Computes SHAP values for the input tuple with custom KernelSHAP.Options.
      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).
      Throws:
      UnsupportedOperationException - if SHAP explanations are not supported.
    • infer

      Prediction infer(Tuple x, boolean probability, boolean explain)
      Performs inference on a single tuple.
      Parameters:
      x - the input tuple.
      probability - true to compute posterior probabilities for soft classifiers.
      explain - true to compute feature explanations.
      Returns:
      the prediction.
    • infer

      default Prediction infer(Tuple x, boolean probability, boolean explain, KernelSHAP.Options options)
      Performs inference on a single tuple with custom KernelSHAP.Options.
      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

      default Prediction infer(Tuple x, boolean probability)
      Performs inference on a single tuple without explanations.
      Parameters:
      x - the input tuple.
      probability - true to compute posterior probabilities for soft classifiers.
      Returns:
      the prediction.
    • infer

      default Prediction infer(Tuple x)
      Performs inference on a single tuple.
      Parameters:
      x - the input tuple.
      Returns:
      the prediction.
    • infer

      default Prediction[] infer(DataFrame data, boolean probability, boolean explain)
      Performs batch inference over a data frame.
      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

      default Prediction[] infer(DataFrame data, boolean probability, boolean explain, KernelSHAP.Options options)
      Performs batch inference over a data frame with custom KernelSHAP.Options.
      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.
    • infer

      default Prediction[] infer(DataFrame data, boolean probability)
      Performs batch inference over a data frame without explanations.
      Parameters:
      data - the input data frame.
      probability - true to compute posterior probabilities for soft classifiers.
      Returns:
      an array of predictions.
    • infer

      default Prediction[] infer(DataFrame data)
      Performs batch inference over a data frame.
      Parameters:
      data - the input data frame.
      Returns:
      an array of predictions.
    • classification

      static ClassificationModel classification(String algorithm, Formula formula, DataFrame data, DataFrame test, Properties params, int kfold, int round, boolean ensemble)
      Trains a classification model. When kfold >= 2, k-fold cross-validation is performed and the validation metrics are recorded.
      Parameters:
      algorithm - the learning algorithm.
      formula - the model formula.
      data - the training data.
      test - the optional test data. May be null.
      params - the hyperparameters.
      kfold - number of folds for cross-validation; skipped when kfold < 2.
      round - the number of repeated cross-validation rounds.
      ensemble - if true, the cross-validation fold models are combined into an ensemble; otherwise the final model is retrained on the full training set.
      Returns:
      the classification model.
    • classification

      static ClassificationModel classification(String algorithm, Formula formula, DataFrame data, DataFrame test, Properties params)
      Trains a classification model.
      Parameters:
      algorithm - the learning algorithm.
      formula - the model formula.
      data - the training data.
      test - the optional test data.
      params - the hyperparameters.
      Returns:
      the classification model.
    • classification

      static DataFrameClassifier classification(String algorithm, Formula formula, DataFrame data, Properties params)
      Trains a classification model.
      Parameters:
      algorithm - the learning algorithm.
      formula - the model formula.
      data - the training data.
      params - the hyperparameters.
      Returns:
      the classification model.
    • regression

      static RegressionModel regression(String algorithm, Formula formula, DataFrame data, DataFrame test, Properties params, int kfold, int round, boolean ensemble)
      Trains a regression model. When kfold >= 2, k-fold cross-validation is performed and the validation metrics are recorded.
      Parameters:
      algorithm - the learning algorithm.
      formula - the model formula.
      data - the training data.
      test - the optional test data. May be null.
      params - the hyperparameters.
      kfold - number of folds for cross-validation; skipped when kfold < 2.
      round - the number of repeated cross-validation rounds.
      ensemble - if true, the cross-validation fold models are combined into an ensemble; otherwise the final model is retrained on the full training set.
      Returns:
      the regression model.
    • regression

      static RegressionModel regression(String algorithm, Formula formula, DataFrame data, DataFrame test, Properties params)
      Trains a regression model.
      Parameters:
      algorithm - the learning algorithm.
      formula - the model formula.
      data - the training data.
      test - the optional test data.
      params - the hyperparameters.
      Returns:
      the regression model.
    • regression

      static DataFrameRegression regression(String algorithm, Formula formula, DataFrame data, Properties params)
      Trains a regression model.
      Parameters:
      algorithm - the learning algorithm.
      formula - the model formula.
      data - the training data.
      params - the hyperparameters.
      Returns:
      the regression model.
    • clustering

      static ClusteringModel clustering(String algorithm, Formula formula, DataFrame data, Properties params)
      Trains a centroid-based clustering model.
      Parameters:
      algorithm - the clustering algorithm ("kmeans", "xmeans", "gmeans", "deterministic-annealing", or "da").
      formula - the feature selection formula; if null, all columns are included.
      data - the training data.
      params - the hyperparameters.
      Returns:
      the clustering model.
    • fitClustering

      static CentroidClustering<double[],double[]> fitClustering(String algorithm, double[][] x, Properties params)
      Fits a centroid-based clustering algorithm on a numeric feature matrix.
      Parameters:
      algorithm - the clustering algorithm ("kmeans", "xmeans", "gmeans", "deterministic-annealing", or "da").
      x - the input feature matrix.
      params - the hyperparameters.
      Returns:
      the fitted centroid clustering.
    • quantizer

      static VectorQuantizerModel quantizer(String algorithm, Formula formula, DataFrame data, Properties params)
      Trains a vector quantization model.
      Parameters:
      algorithm - the vector quantizer algorithm ("som", "neural-gas", "growing-neural-gas", "gng", "neural-map", or "birch").
      formula - the feature selection formula; if null, all columns are included.
      data - the training data.
      params - the hyperparameters.
      Returns:
      the vector quantization model.
    • fitQuantizer

      static VectorQuantizer fitQuantizer(String algorithm, double[][] x, Properties params)
      Fits a vector quantization algorithm on a numeric feature matrix.
      Parameters:
      algorithm - the vector quantizer algorithm ("som", "neural-gas", "growing-neural-gas", "gng", "neural-map", or "birch").
      x - the input feature matrix.
      params - the hyperparameters.
      Returns:
      the fitted vector quantizer.
    • anomaly

      static AnomalyModel anomaly(String algorithm, Formula formula, DataFrame data, Properties params)
      Trains an anomaly detection model.
      Parameters:
      algorithm - the anomaly detection algorithm ("isolation-forest", "iforest", "lof", "ocsvm", or "one-class-svm").
      formula - the feature selection formula; if null, all columns are included.
      data - the training data.
      params - the hyperparameters.
      Returns:
      the anomaly detection model.
    • fitAnomaly

      static Serializable fitAnomaly(String algorithm, double[][] x, Properties params)
      Fits an anomaly detection algorithm on a numeric feature matrix.
      Parameters:
      algorithm - the anomaly detection algorithm ("isolation-forest", "iforest", "lof", "ocsvm", or "one-class-svm").
      x - the input feature matrix.
      params - the hyperparameters.
      Returns:
      the fitted anomaly detector.