Interface Model
- All Known Implementing Classes:
AnomalyModel, ClassificationModel, ClusteringModel, RegressionModel, VectorQuantizerModel
public interface Model
Generic model interface.
-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionReturns the algorithm name.static AnomalyModelanomaly(String algorithm, Formula formula, DataFrame data, Properties params) Trains an anomaly detection model.static DataFrameClassifierclassification(String algorithm, Formula formula, DataFrame data, Properties params) Trains a classification model.static ClassificationModelclassification(String algorithm, Formula formula, DataFrame data, DataFrame test, Properties params) Trains a classification model.static ClassificationModelclassification(String algorithm, Formula formula, DataFrame data, DataFrame test, Properties params, int kfold, int round, boolean ensemble) Trains a classification model.static ClusteringModelclustering(String algorithm, Formula formula, DataFrame data, Properties params) Trains a centroid-based clustering model.static SerializablefitAnomaly(String algorithm, double[][] x, Properties params) Fits an anomaly detection algorithm on a numeric feature matrix.static CentroidClustering<double[], double[]> fitClustering(String algorithm, double[][] x, Properties params) Fits a centroid-based clustering algorithm on a numeric feature matrix.static VectorQuantizerfitQuantizer(String algorithm, double[][] x, Properties params) Fits a vector quantization algorithm on a numeric feature matrix.formula()Returns the model formula.default StringReturns the model metadata tag.default StringReturns the model metadata tag.default Prediction[]Performs batch inference over a data frame.default Prediction[]Performs batch inference over a data frame without explanations.default Prediction[]Performs batch inference over a data frame.default Prediction[]infer(DataFrame data, boolean probability, boolean explain, KernelSHAP.Options options) Performs batch inference over a data frame with customKernelSHAP.Options.default PredictionPerforms inference on a single tuple.default PredictionPerforms inference on a single tuple without explanations.Performs inference on a single tuple.default Predictioninfer(Tuple x, boolean probability, boolean explain, KernelSHAP.Options options) Performs inference on a single tuple with customKernelSHAP.Options.default booleanisOnline()Returns true if this model supports online learning updates.static VectorQuantizerModelquantizer(String algorithm, Formula formula, DataFrame data, Properties params) Trains a vector quantization model.static DataFrameRegressionregression(String algorithm, Formula formula, DataFrame data, Properties params) Trains a regression model.static RegressionModelregression(String algorithm, Formula formula, DataFrame data, DataFrame test, Properties params) Trains a regression model.static RegressionModelregression(String algorithm, Formula formula, DataFrame data, DataFrame test, Properties params, int kfold, int round, boolean ensemble) Trains a regression model.schema()Returns the schema of input data (without response variable).default voidSets a model metadata tag.default ObjectComputes SHAP values for the input tuple.default Objectshap(Tuple x, KernelSHAP.Options options) Computes SHAP values for the input tuple with customKernelSHAP.Options.default booleanReturns true if this model supports SHAP feature explanations.tags()Returns the model metadata tags.default voidOnline updates the model sequentially with a data frame of observations.default voidOnline updates the model with a single observation.
-
Field Details
-
ID
-
VERSION
-
-
Method Details
-
algorithm
-
schema
StructType schema()Returns the schema of input data (without response variable).- Returns:
- the schema of input data (without response variable).
-
formula
-
tags
-
getTag
-
getTag
-
setTag
-
isOnline
default boolean isOnline()Returns true if this model supports online learning updates.- Returns:
- true if online learning is supported.
-
update
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
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
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
Computes SHAP values for the input tuple with customKernelSHAP.Options.- Parameters:
x- the input tuple.options- the KernelSHAP options, ornullto use default options.- Returns:
- the SHAP values (double[] for regression, double[][] for classification).
- Throws:
UnsupportedOperationException- if SHAP explanations are not supported.
-
infer
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
Performs inference on a single tuple with customKernelSHAP.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 benull).- Returns:
- the prediction.
-
infer
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
Performs inference on a single tuple.- Parameters:
x- the input tuple.- Returns:
- the prediction.
-
infer
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 customKernelSHAP.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 benull).- Returns:
- an array of predictions.
-
infer
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
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. Whenkfold >= 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 benull.params- the hyperparameters.kfold- number of folds for cross-validation; skipped whenkfold < 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. Whenkfold >= 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 benull.params- the hyperparameters.kfold- number of folds for cross-validation; skipped whenkfold < 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; ifnull, 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; ifnull, all columns are included.data- the training data.params- the hyperparameters.- Returns:
- the vector quantization model.
-
fitQuantizer
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
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; ifnull, all columns are included.data- the training data.params- the hyperparameters.- Returns:
- the anomaly detection model.
-
fitAnomaly
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.
-