predict.fastPLS: Predict from fitted fastPLS models

View source: R/main.R

predict.fastPLSR Documentation

Predict from fitted fastPLS models

Description

Generates predictions for new samples from fitted PLS-SVD, SIMPLS-family, OPLS, or kernel PLS models. Stored centering, scaling, latent projections, and model-specific filtering are applied before producing numeric response predictions or classification labels.

Usage

## S3 method for class 'fastPLS'
predict(
  object,
  newdata,
  Ytest = NULL,
  proj = FALSE,
  backend = NULL,
  n.cores = NULL,
  top = NULL,
  raw_scores = FALSE,
  ...
)

Arguments

object

A fitted fastPLS, fastPLSKernel, or fastPLSOpls object.

newdata

Numeric predictor matrix.

Ytest

Optional observed response. When supplied, the predictions are passed to evaluate() and its complete result is returned in metrics. Regression Q2Y is referenced to the response mean stored during model training.

proj

Logical; return projected Ttest when TRUE.

backend

Prediction backend: "cpu", "cuda", or "metal". Operation-split Metal models predict on CPU because their retained matrices are host-accessible; Metal is used for fitting sample-matrix products. When omitted, an explicit session backend setting is used, followed by the FASTPLS_BACKEND environment variable; otherwise CPU is used. Prediction must use the backend that fitted the model. An unavailable CUDA or Metal selection raises an error; prediction is never silently moved to CPU.

n.cores

Number of CPU cores requested for compiled host operations. An explicit value takes precedence over options(n.cores = ...). This controls supported BLAS/OpenMP host work and does not set CUDA or Metal device parallelism.

top

Number of ranked classes to return for classification. The default NULL returns only the predicted class in Ypred. A positive integer greater than one additionally returns that many ordered classes per sample in Ypred_top; top = 5, for example, returns five classes. This argument is ignored with a warning for regression models.

raw_scores

If TRUE, keep raw classification score cubes as Yscore when available. This can require substantial memory. With raw_scores = FALSE, ranked classification is evaluated in bounded row blocks for both float64 and float32 inputs, and only the requested ranks are retained.

...

Required by the S3 generic. Additional arguments are not supported and produce an error, which prevents obsolete or misspelled options from being silently ignored.

Value

A list containing Ypred, optional independent-test Q2Y, optional Ttest, optional Ypred_top and Ypred_top_score ranked-class outputs, and optional raw classification scores. When Ytest is supplied, metrics contains the complete result returned by evaluate() for every requested component count. For a rank-limited PLS-LDA fit, the prediction path retains every requested position and repeats the last estimable class prediction and discriminant scores.

Examples

X <- as.matrix(mtcars[, c("disp", "hp", "wt", "qsec")])
y <- mtcars$mpg
fit <- pls(X, y,
    ncomp = 2, method = "simpls", backend = "cpu",
    return_variance = FALSE
)
pred <- predict(fit, X[seq_len(3), , drop = FALSE])
pred$Ypred

fastPLS documentation built on Sept. 29, 2026, 1:06 a.m.