pcr — Principal Components Regression

Group: Core PLS · Registry tolerance: 1e-06

Description

Principal Components Regression

Registry note — PCR via SVD on X then linear regression; references are sklearn Pipeline(PCA(svd_solver=’full’) + LinearRegression) and R pls::pcr.

Parameters

Name

Type

Default

Notes

X

—

required

current public binding signature

y

—

required

current public binding signature

n_components

int

2

current public binding signature

center_x

bool | None

True

current public binding signature

scale_x

bool | None

True

current public binding signature

center_y

bool | None

True

current public binding signature

scale_y

bool | None

False

current public binding signature

Explanations

Bibliographic source

Massy, W. F. (1965). Principal components regression in exploratory statistical research. Journal of the American Statistical Association 60(309), 234–256. DOI 10.1080/01621459.1965.10480787.

Mathematical principle

PCR first computes a truncated singular-value decomposition of the centred predictor matrix, \(\mathbf X=\mathbf U\boldsymbol\Sigma\mathbf V^\top\), and regresses Y on the first \(k\) scores \(\mathbf T_k=\mathbf U_k\boldsymbol\Sigma_k\). The coefficient matrix is therefore \(\mathbf B=\mathbf V_k\boldsymbol\Sigma_k^{-1}\mathbf U_k^\top\mathbf Y=\mathbf V_k\boldsymbol\Sigma_k^{-2}\mathbf T_k^\top\mathbf Y\). Components are ordered by predictor variance without using Y, which is the defining contrast with PLS.

Appropriate uses

Baseline regression after unsupervised variance compression, especially when comparison with response-guided PLS is informative.

Limits and validation

High-variance PCs need not predict Y, so PCR can discard low-variance predictive directions.

Implementation

The current PCR path uses the library’s SVD/eigendecomposition machinery and returns a linear coefficient matrix with training means for prediction. The retained singular values must be nonzero.

Sources and provenance

Current implementation: cpp/src/core/model.cpp.

API and bindings

C ABI (ABI 2): n4m_estimators_pcr_fit. Use the linked public header for the exact signature, configuration, and result handles.

Python (verified public re-export):

from n4m.estimators.regression.latent import pcr
result = pcr(X, y)

Source signature: pcr(X, y, *, n_components: int = 2, center_x: bool | None = True, scale_x: bool | None = True, center_y: bool | None = True, scale_y: bool | None = False) (n4m/_impl/native.py).

R (source-verified): pcr(formula, ncomp = 2L, data, subset, na.action = stats::na.omit, method = c("svdpc", "pcr"), scale = FALSE, validation = c("none", "CV"), segments = 10L, center = TRUE, fit_components = TRUE, ...).

The source signature has additional required inputs, so no example call is fabricated.

MATLAB / Octave (source-verified): pcr(X, Y, n_components).

The source signature has additional required inputs, so no example call is fabricated.

Registry parity references 📐

  • 📐 ref.python_scikit_learn (python · python) — scikit-learn 1.7.2 · strict (rmse_rel ≤ 1e-06) — sklearn Pipeline(PCA(svd_solver=’full’) + LinearRegression).

  • 📐 ref.r_pls (R · r) — pls 2.8.5 · strict (rmse_rel ≤ 1e-06) — R pls::pcr(scale=FALSE).

Benchmarks

Archived measurement identity. Backend labels in this table are the raw IDs recorded when the benchmark ran (including historical pls4all.* IDs). They preserve measurement provenance and do not describe a current public Python, R, or MATLAB binding; use the source-verified API and bindings section above for current entry points.

Adaptive wall-clock per cell measured against full_matrix.csv. 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 = archived binding-harness result agrees with the C++ baseline  ·  ⇄ cross-check = documented by-design selector/RNG/model, noncanonical API/facade convention, or secondary oracle  ·  ✗ divergent  ·  ⚠ error  ·  — not run. The fastest backend per column is marked 🏆.

Reference gate: strict — numeric equivalence (rmse_rel_tol ≤ 1e-06).

Rows tagged with 📐 are the canonical parity references for this method (declared in parity_timing.registry). C++ and external rows show reference parity; archived language-harness rows show binding parity against the C++ backend. Hover the icon for role and tolerance band.

BackendParity200×50 (ms)
C++ native · libn4m
pls4all.cpp.blas+omp✓ ref 3e-122.92 ms
Python · archived pls4all benchmark
pls4all.python✓ bind2.95 ms
pls4all.sklearn✓ bind2.68 ms🏆
R · archived pls4all benchmark
pls4all.R✓ 2e-155.15 ms
pls4all.R.formula✓ 2e-156.41 ms
pls4all.R.mdatools✓ 2e-156.21 ms
pls4all.R.pls✓ 2e-1511.8 ms
Python · external
📐ref.python_scikit_learnsource2.71 ms
R · external
📐ref.r_pls⇄ +2e-147.99 ms
BackendParity200×50 (ms)
C++ native · libn4m
pls4all.cpp.blas+omp✓ ref 3e-122.52 ms
Python · archived pls4all benchmark
pls4all.python✓ bind2.50 ms🏆
pls4all.sklearn✓ bind2.72 ms
R · archived pls4all benchmark
pls4all.R✓ 2e-155.09 ms
pls4all.R.formula✓ 2e-156.36 ms
pls4all.R.mdatools✓ 2e-156.27 ms
pls4all.R.pls✓ 2e-1510.4 ms
Python · external
📐ref.python_scikit_learnsource2.85 ms
R · external
📐ref.r_pls⇄ +2e-147.83 ms
BackendParity200×50 (ms)
C++ native · libn4m
pls4all.cpp.blas+omp✓ ref 3e-122.49 ms🏆
Python · archived pls4all benchmark
pls4all.python✓ bind2.73 ms
pls4all.sklearn✓ bind2.67 ms
R · archived pls4all benchmark
pls4all.R✓ 2e-154.86 ms
pls4all.R.formula✓ 2e-155.87 ms
pls4all.R.mdatools✓ 2e-156.40 ms
pls4all.R.pls✓ 2e-1510.7 ms
Python · external
📐ref.python_scikit_learnsource4.94 ms
R · external
📐ref.r_pls⇄ +2e-1414.0 ms

See also: benchmark overview · methods index · interactive dashboard