# `pls` — PLS regression (SIMPLS) _Group_: **Core PLS** · _Registry tolerance_: `0.1` ## Description SIMPLS PLS regression baseline From the `pls4all.sklearn.PLSRegression` docstring: > Partial Least Squares regression backed by `pls4all`'s C core.
Full Python sklearn-wrapper docstring ```text Partial Least Squares regression backed by `pls4all`'s C core. Drop-in replacement for `sklearn.cross_decomposition.PLSRegression` with two distinguishing knobs: * `solver` selects the inner algorithm (NIPALS, SIMPLS, SVD, …) directly — sklearn only exposes 'nipals' / 'svd'. * Round-trip via `pickle.dumps` is bit-exact, backed by the C ABI `.n4a` bundle (`n4m_model_export_to_buffer`). Parameters ---------- n_components : int, default=2 Number of latent components. solver : str, default='simpls' One of 'nipals', 'simpls', 'orthogonal-scores', 'kernel', 'wide-kernel', 'svd', 'power', 'randomized-svd'. center_x, scale_x : bool, default=True Standardize X columns to zero mean / unit variance. center_y : bool, default=True Center y to zero mean. scale_y : bool, default=False Standardize y columns to unit variance. tol : float, default=1e-6 Convergence tolerance for iterative solvers. max_iter : int, default=500 Max NIPALS iterations. store_scores : bool, default=False Keep the latent score matrices (`x_scores_`) after fit. ```
> **Registry note** — Baseline SIMPLS cell. sklearn uses NIPALS and ikpls uses improved-kernel PLS, so exact bit parity is not expected; the row exists to anchor timing comparisons. ### Parameters | Name | Type | Default | Notes | |------|------|---------|-------| | `n_components` | `int` | `2` | Number of latent components extracted (k). | | `solver` | `str` | `'simpls'` | Inner algorithm: 'nipals', 'simpls', 'svd', 'kernel', 'orthogonal-scores', 'power', 'randomized-svd', 'wide-kernel'. | | `center_x` | `bool` | `True` | Subtract the column mean of X before fitting. | | `scale_x` | `bool` | `True` | Standardize X columns to unit variance before fitting. | | `center_y` | `bool` | `True` | Subtract the column mean of y before fitting. | | `scale_y` | `bool` | `False` | Standardize y columns to unit variance before fitting. | | `tol` | `float` | `1e-06` | Convergence tolerance for iterative solvers (NIPALS / power-iteration). | | `max_iter` | `int` | `500` | Maximum iterations for iterative solvers. | | `store_scores` | `bool` | `False` | If True, keep the latent score matrix (`x_scores_`) after fit. | ## Explanations ### Bibliographic source de Jong, S. (1993). *SIMPLS: an alternative approach to partial least squares regression*. Chemometrics and Intelligent Laboratory Systems 18(3), 251–263. ### Mathematical principle Partial Least Squares regression seeks a set of latent directions in the predictor space that maximise the *covariance* with the response, in contrast to PCA which maximises only the variance of $\mathbf{X}$. Given centred $\mathbf{X} \in \mathbb{R}^{n\times p}$ and $\mathbf{Y} \in \mathbb{R}^{n\times q}$, the first PLS component is the unit-norm direction $\mathbf{w}_1$ maximising $\operatorname{Cov}(\mathbf{X}\mathbf{w}_1, \mathbf{Y})$. Closed form: $\mathbf{w}_1 \propto \mathbf{X}^{\top}\mathbf{Y}$ (or its dominant left singular vector when $q>1$). Subsequent components are extracted from the deflated residual matrix so the resulting scores $\mathbf{T} = \mathbf{X}\mathbf{W}$ are orthogonal. **SIMPLS** (de Jong 1993) is algebraically equivalent to NIPALS but computes the loading weights directly from the cross-product $\mathbf{S} = \mathbf{X}^{\top}\mathbf{Y}$ without re-deflating $\mathbf{X}$ at each step. This avoids accumulating floating-point error from iterative deflation and runs in roughly half the time of NIPALS for the same number of components. SIMPLS is the variant exposed by MATLAB's `plsregress`. Once $k$ latent scores have been extracted the regression coefficients are reconstructed as $\mathbf{B} = \mathbf{W}(\mathbf{P}^{\top}\mathbf{W})^{-1}\mathbf{Q}^{\top}$, where $\mathbf{P}, \mathbf{Q}$ are the X- and Y-loadings. Predictions on new $\mathbf{X}^{\star}$ follow $\hat{\mathbf{Y}} = \mathbf{X}^{\star}\mathbf{B} + \bar{\mathbf{y}}$. The choice of $k$ trades bias and variance: use cross-validated PRESS or the one-SE rule of Hastie et al. (2009) to select it. ### Implementation Dispatched through `Algorithm.PLS_REGRESSION` + `Solver.SIMPLS` in libn4m (the `n4m_pls_fit` C entry point). The same `Model.fit` / `Model.predict` surface is used by every binding. NIPALS, SVD, power-iteration, randomised-SVD, orthogonal-scores, kernel and wide-kernel solver variants are all available — see the `Solver` enum. MATLAB header (`bindings/matlab/+pls4all/Regression.m`): ```text pls4all.Regression — Statistics Toolbox-style class for PLS regression. Tier-2 idiomatic MATLAB / Octave wrapper around the tier-1 pls4all.pls_fit(X, Y, n_components) primitive. Mirrors the shape of MATLAB's built-in RegressionPartialLeastSquares: object-oriented properties + methods, factory function `pls4all.fitrpls`, and a ``` ### Usage Every pls4all binding tab dispatches into the same C kernel; the external libraries listed at the bottom of the page are the parity references registered in `benchmarks.parity_timing.registry`. Switch tabs to read the same fit in your language. The R package now ships drop-in-compatible facades for the CRAN `pls` package (`plsr`, `pcr`, `mvr`) and for the `mdatools::pls(x, y, ...)` matrix idiom — those tabs appear only on the methods that have a meaningful equivalence. **pls4all bindings** ::::{tab-set} :class: pls4all-bindings :::{tab-item} C ABI · libn4m :sync: c :class-label: lang-c ```c /* C ABI — libn4m (Model.fit path) */ n4m_context_t* ctx = n4m_context_create(); n4m_config_t* cfg = n4m_config_create(); n4m_config_set_algorithm(cfg, N4M_ALGORITHM_PLS_REGRESSION); n4m_config_set_solver (cfg, N4M_SOLVER_SIMPLS); n4m_config_set_n_components(cfg, 4); n4m_model_t* mdl = NULL; n4m_model_fit(ctx, cfg, &x_view, &y_view, &mdl); n4m_model_predict(ctx, mdl, &x_test_view, &y_hat_view); n4m_model_destroy(mdl); n4m_config_destroy(cfg); n4m_context_destroy(ctx); ``` ::: :::{tab-item} Python · pls4all (raw) :sync: python-raw :class-label: lang-python ```python import pls4all from pls4all import Algorithm, Solver with pls4all.Context() as ctx, pls4all.Config() as cfg: cfg.algorithm = Algorithm.PLS_REGRESSION cfg.solver = Solver.SIMPLS cfg.n_components = 4 with pls4all.Model.fit(ctx, cfg, X, y) as mdl: y_hat = mdl.predict(X_test) ``` ::: :::{tab-item} Python · n4m direct :sync: python-n4m :class-label: lang-python ```python import n4m from n4m.sklearn import NativePLSRegressor # Fixed component count through the moment sweep path. res = n4m.pls(X, y, n_components=4, cv=5) coef = res["coefficients"] # Reusable estimator; predict() replays X @ coefficients + intercept. model = NativePLSRegressor(n_components=4, cv=5).fit(X, y) y_hat = model.predict(X_test) # Optional train-CV component grid, still train-only and moment-based. model_grid = NativePLSRegressor(pls_components=(1, 2, 3, 4), cv=5).fit(X, y) ``` ::: :::{tab-item} Python · pls4all.sklearn :sync: python-sklearn :class-label: lang-python ```python from pls4all.sklearn import PLSRegression mdl = PLSRegression(n_components=2, solver='simpls', center_x=True, scale_x=True, center_y=True, scale_y=False, tol=1e-06, max_iter=500, store_scores=False) mdl.fit(X, y) y_hat = mdl.predict(X_test) ``` ::: :::{tab-item} R · pls4all_method() :sync: r-dispatcher :class-label: lang-r ```r library(pls4all) # Unified low-level dispatcher (May 2026 R cleanup): res <- pls4all_method("pls", X, y, n_components = 4L) # res is a named list with MethodResult arrays/scalars. # selected_indices / top_k_intervals are 1-based. ``` ::: :::{tab-item} R · `pls` package compat :sync: r-pls-compat :class-label: lang-r ```r library(pls4all) # Drop-in for CRAN `pls::plsr` (same signature). fit <- plsr(y ~ ., ncomp = 4L, data = train, validation = "CV", segments = 10L) yhat <- predict(fit, newdata = test, ncomp = 4L) RMSEP(fit) ``` ::: :::{tab-item} R · `mdatools` compat :sync: r-mdatools :class-label: lang-r ```r library(pls4all) # Drop-in for `mdatools::pls(x, y, ncomp, method = "simpls")`. fit <- pls_mdatools(X, y, ncomp = 4L, method = "simpls", center = TRUE, scale = FALSE) yhat <- predict(fit, newdata = X_test, ncomp = 4L) ``` ::: :::{tab-item} MATLAB · pls4all (MEX) :sync: matlab-mex :class-label: lang-matlab ```matlab res = pls4all.pls_fit(X, y, 4); % see header of bindings/matlab/+pls4all/pls_fit.m for full % parameter surface: % [coefs, x_mean, y_mean, predictions] = pls_fit(X, Y, n_components) yhat = predict(res, Xtest); ``` ::: :::{tab-item} MATLAB · pls4all (classdef) :sync: matlab-classdef :class-label: lang-matlab ```matlab mdl = pls4all.fit("pls", X, y, "NumComponents", 4); yhat = predict(mdl, Xtest); ``` ::: :::: **Registry parity references** 📐 :::{card} :class-card: external-refs - 📐 **`ref.python_ikpls`** (python · ikpls) — `ikpls` 4.0.1.post1 · qualitative (rmse_rel ≤ 1e-01) — ikpls.numpy_ikpls.PLS algorithm 1. - 📐 **`ref.python_scikit_learn`** (python · python) — `scikit-learn` 1.8.0 · qualitative (rmse_rel ≤ 1e-01) — sklearn.cross_decomposition.PLSRegression(scale=False). - 📐 **`ref.r_mixomics`** (R · mixOmics) — `mixOmics` 6.26.0 · qualitative (rmse_rel ≤ 1e-01) — Bioconductor mixOmics::pls(mode='regression', scale=FALSE). - 📐 **`ref.r_pls`** (R · r) — `pls` 2.8.5 · qualitative (rmse_rel ≤ 1e-01) — R pls::plsr(method='simpls', scale=FALSE). ::: ### Benchmarks Adaptive wall-clock per cell measured against [`full_matrix.csv`](../benchmarks/overview.md). Only backends that implement this method are listed; libraries without the method are omitted. **Verdict**  ·  ✓ ref / ≈ ref / ~ shape mark a reference-gate pass at strict / relaxed / qualitative tolerance  ·  ✓ bind = pls4all binding agrees with the C++ baseline  ·  ✗ divergent  ·  ⚠ error  ·  — not run. The fastest backend per column is marked 🏆. **Reference gate**: qualitative — shape/smoke comparison only. The external library and pls4all do not produce numerically equivalent output for this method (see the MethodSpec notes); the `rmse_rel_tol ≤ 1e-01` budget is set wide on purpose. Treat ~ shape as *“we ran both, both finished”*, not as numerical agreement. Rows tagged with **📐** are the canonical parity references for this method (declared in [`parity_timing.registry`](../benchmarks/methodology.md)). C++ and external rows show reference parity; pls4all language bindings show binding parity against the C++ backend. Hover the icon for role and tolerance band. ::::{tab-set} :class: parity-tabs :::{tab-item} 1 thread :sync: threads-1
BackendParity50×250 (ms)100×50 (ms)100×500 (ms)100×2500 (ms)200×50 (ms)250×50 (ms)500×50 (ms)500×500 (ms)500×2500 (ms)2500×50 (ms)2500×500 (ms)2500×2500 (ms)10000×50 (ms)10000×500 (ms)
C++ native · libn4m
pls4all.cpp.blas≈ +1e-152.58 ms1.47 ms9.48 ms44.2 ms🏆1.86 ms2.57 ms4.17 ms🏆44.0 ms243.3 ms20.5 ms🏆229.3 ms🏆1.2 s99.8 ms1.1 s
pls4all.cpp.blas+omp≈ +1e-152.40 ms🏆1.37 ms8.86 ms45.5 ms1.88 ms2.53 ms4.52 ms43.3 ms🏆220.7 ms🏆22.2 ms237.4 ms1.2 s🏆89.8 ms🏆1.2 s
pls4all.cpp.omp≈ +1e-152.69 ms1.44 ms10.0 ms44.7 ms1.76 ms🏆2.61 ms4.40 ms48.4 ms226.7 ms24.5 ms236.4 ms1.3 s92.8 ms1.1 s🏆
pls4all.cpp.ref≈ +1e-152.89 ms1.33 ms🏆8.07 ms🏆47.4 ms1.98 ms2.52 ms🏆4.35 ms45.6 ms224.4 ms20.9 ms243.5 ms1.3 s97.3 ms1.1 s
Python · pls4all
pls4all.python✓ bind2.86 ms1.91 ms3.01 ms
pls4all.sklearn✓ bind2.65 ms2.82 ms3.00 ms
R · pls4all
pls4all.R✓ 7e-1510.3 ms6.95 ms9.36 ms
pls4all.R.formula✓ 7e-1521.8 ms8.60 ms10.1 ms
pls4all.R.mdatools✓ 7e-1518.2 ms12.1 ms9.58 ms
pls4all.R.pls✓ 7e-1537.0 ms17.9 ms18.6 ms
MATLAB · pls4all
pls4all.matlab✗ +9e+004.19 ms3.28 ms4.59 ms
pls4all.matlab.classdef✗ +9e+004.45 ms3.45 ms4.58 ms
Python · external
📐ref.python_ikpls⚠ +9e-032.27 ms
📐ref.python_scikit_learnsource3.54 ms3.76 ms2.99 ms
R · external
📐ref.r_mixomics~ shape 6e-1614.9 ms
📐ref.r_pls~ shape 3e-0225.4 ms12.7 ms12.7 ms
MATLAB · external
plsregress~ shape 5e-145.22 ms4.52 ms
::: :::{tab-item} 3 threads :sync: threads-3
BackendParity50×250 (ms)100×50 (ms)100×500 (ms)100×2500 (ms)200×50 (ms)250×50 (ms)500×50 (ms)500×500 (ms)500×2500 (ms)2500×50 (ms)2500×500 (ms)2500×2500 (ms)10000×50 (ms)10000×500 (ms)
C++ native · libn4m
pls4all.cpp.blas~ shape 6e-163.26 ms
pls4all.cpp.blas+omp~ shape 6e-161.85 ms
pls4all.cpp.omp~ shape 1e-151.88 ms
pls4all.cpp.ref~ shape 1e-151.77 ms🏆
Python · pls4all
pls4all.python✓ 7e-151.88 ms
pls4all.sklearn✓ 7e-152.21 ms
R · pls4all
pls4all.R✓ bind6.50 ms
pls4all.R.formula✓ bind9.14 ms
pls4all.R.mdatools✓ 5e-159.44 ms
pls4all.R.pls✓ 5e-1515.0 ms
MATLAB · pls4all
pls4all.matlab✗ +9e+003.50 ms
pls4all.matlab.classdef✗ +9e+004.44 ms
Python · external
📐ref.python_ikpls~ shape 9e-032.30 ms
📐ref.python_scikit_learnsource2.59 ms
R · external
📐ref.r_mixomics~ shape 6e-1613.7 ms
📐ref.r_pls~ shape 3e-0211.9 ms
::: :::{tab-item} 10 threads :sync: threads-10
BackendParity50×250 (ms)100×50 (ms)100×500 (ms)100×2500 (ms)200×50 (ms)250×50 (ms)500×50 (ms)500×500 (ms)500×2500 (ms)2500×50 (ms)2500×500 (ms)2500×2500 (ms)10000×50 (ms)10000×500 (ms)
C++ native · libn4m
pls4all.cpp.blas~ shape 6e-161.71 ms
pls4all.cpp.blas+omp~ shape 6e-161.71 ms
pls4all.cpp.omp~ shape 1e-151.69 ms🏆
pls4all.cpp.ref~ shape 1e-151.71 ms
Python · pls4all
pls4all.python✓ bind1.73 ms
pls4all.sklearn✓ bind1.94 ms
R · pls4all
pls4all.R✓ 7e-154.95 ms
pls4all.R.formula✓ 7e-156.19 ms
pls4all.R.mdatools✓ 7e-157.04 ms
pls4all.R.pls✓ 7e-1511.6 ms
MATLAB · pls4all
pls4all.matlab✗ +9e+002.86 ms
pls4all.matlab.classdef✗ +9e+003.21 ms
Python · external
📐ref.python_ikpls~ shape 9e-031.89 ms
📐ref.python_scikit_learnsource2.21 ms
R · external
📐ref.r_mixomics~ shape 6e-1612.7 ms
📐ref.r_pls~ shape 3e-028.49 ms
::: :::: --- _See also_: [benchmark overview](../benchmarks/overview.md) · [methods index](index.md) · [interactive dashboard](../landing/dashboard.md)