Skip to main content

Improved Kernel Partial Least Squares (IKPLS) and Fast Cross-Validation

PyPI Version

Python Versions

Pepy - Total Downloads

PyPI - Downloads

License

Documentation Status

CodeFactor

Tests Status

Test Coverage

Package Status

JOSS Status

The ikpls software package provides fast and efficient tools for PLS (Partial Least Squares) modeling. This package is designed to help researchers and practitioners handle PLS modeling faster than previously possible - particularly on large datasets.

Citation

Unlock the Power of Fast and Stable Partial Least Squares Modeling with IKPLS

Dive into cutting-edge Python implementations of the IKPLS (Improved Kernel Partial Least Squares) Algorithms #1 and #2 [1] for CPUs, GPUs, and TPUs. IKPLS is both fast [2] and numerically stable [3] making it optimal for PLS modeling.

  • Use our NumPy [4] based CPU implementations for fast PLS on the CPU, and our scikit-learn-conformant ikpls.sklearn.PLS wrapper for seamless integration with scikit-learn's [5] ecosystem of machine learning algorithms and pipelines. As the wrapper conforms to the scikit-learn estimator API, it can be used with scikit-learn's cross_validate.
  • Use our JAX [6] implementations on CPUs or leverage powerful GPUs and TPUs for PLS modelling. Our JAX implementations are end-to-end differentiable allowing gradient propagation when using PLS as a layer in a deep learning model.
  • Use our combination of NumPy and JAX IKPLS with Engstrøm's and Jensen's unbelievably fast cross-validation algorithm [7] to quickly determine the optimal combination of preprocessing and number of PLS components.
  • Use any of the above in combination with sample-weighted PLS [8].
  • Use our NumPy or JAX implementations for dimensionality reduction to score space with their respective transform methods.
  • Use our NumPy or JAX implementations for reconstruction of original space from score space with their respective inverse_transform methods.

The documentation is available at https://ikpls.readthedocs.io/en/latest/; examples can be found at https://github.com/Sm00thix/IKPLS/tree/main/examples.

Fast Cross-Validation

In addition to the standalone IKPLS implementations, this package contains an implementation of IKPLS combined with the novel, fast cross-validation algorithm by Engstrøm and Jensen [7]. The fast cross-validation algorithm benefit both IKPLS Algorithms and especially Algorithm #2. The fast cross-validation algorithm is mathematically equivalent to the classical cross-validation algorithm. Still, it is much quicker. The fast cross-validation algorithm correctly handles (column-wise) centering and scaling of the $\mathbf{X}$ and $\mathbf{Y}$ input matrices using training set means and standard deviations to avoid data leakage from the validation set. This centering and scaling can be enabled or disabled independently from eachother and for $\mathbf{X}$ and $\mathbf{Y}$ by setting the parameters center_X, center_Y, scale_X, and scale_Y, respectively. In addition to correctly handling (column-wise) centering and scaling, the fast cross-validation algorithm correctly handles row-wise preprocessing that operates independently on each sample such as (row-wise) centering and scaling of the $\mathbf{X}$ and $\mathbf{Y}$ input matrices, convolution, or other preprocessing. Row-wise preprocessing can safely be applied before passing the data to the fast cross-validation algorithm.

Installation

  • Install the package for Python3 using the following command:

    pip3 install ikpls
    
  • Now you can import the NumPy and sklearn implementations with:

    from ikpls.numpy import PLS as NpPLS
    from ikpls.fast_cross_validation.numpy import PLS as NpPLS_FastCV
    
    from ikpls.sklearn import PLS as SkPLS
    
  • You can also install the optional JAX dependency to get JAX implementations of IKPLS

    pip3 install "ikpls[jax]"
    
  • Now, you can import the JAX implementations with:

    # The JAX PLS takes an `algorithm` argument (1 or 2), like the NumPy PLS,
    # e.g. JAXPLS(algorithm=1) or JAXPLS(algorithm=2).
    from ikpls.jax import PLS as JAXPLS
    from ikpls.fast_cross_validation.jax import PLS as JAXPLS_FastCV
    

Prerequisites for JAX

The JAX implementations support running on both CPU, GPU, and TPU.

  • To enable NVIDIA GPU execution, install JAX and CUDA with:

    pip3 install -U "jax[cuda13]"
    
  • To enable Google Cloud TPU execution, install JAX with:

    pip3 install -U "jax[tpu]"
    

These are typical installation instructions that will be what most users are looking for. For customized installations, follow the instructions from the JAX Installation Guide.

To ensure that JAX implementations use float64, set the environment variable JAX_ENABLE_X64=True as per the Common Gotchas. Alternatively, float64 can be enabled with the following function call:

import jax
jax.config.update("jax_enable_x64", True)

Quick Start

Use the ikpls package for PLS modeling

import numpy as np

from ikpls.sklearn import PLS


N = 100  # Number of samples.
K = 50  # Number of features.
M = 10  # Number of targets.
A = 20  # Number of latent variables (PLS components).

X = np.random.uniform(size=(N, K))  # Predictor variables
Y = np.random.uniform(size=(N, M))  # Target variables
w = np.random.uniform(size=(N,))  # Sample weights (optional)

# ikpls.sklearn.PLS is a scikit-learn-conformant estimator wrapping
# ikpls.numpy.PLS, so it plugs straight into Pipeline, GridSearchCV, and
# cross_validate. The number of components is set on the constructor, and
# fit(X, y) follows the scikit-learn API. algorithm=1 or 2 selects the
# Improved Kernel PLS algorithm.
pls = PLS(n_components=A, algorithm=1)
pls.fit(X, Y)  # Pass sample_weight=w for weighted PLS.

# --- Prediction -------------------------------------------------------------

# predict() uses n_components (= A) components. Has shape (N, M) = (100, 10).
Y_pred = pls.predict(X)

# predict_all_components() keeps ikpls's vectorized feature of predicting with
# every number of components 1..A in a single call. Shape (A, N, M) =
# (20, 100, 10); the last slice uses all A components.
Y_pred_all = pls.predict_all_components(X)
(Y_pred_all[A - 1] == Y_pred).all()  # True

# --- Fitted attributes (scikit-learn PLSRegression conventions) -------------

# X weights matrix of shape (K, A) = (50, 20).
pls.x_weights_

# Y weights matrix of shape (M, A) = (10, 20). In Improved Kernel PLS this
# equals y_loadings_, matching sklearn.cross_decomposition.PLSRegression.
pls.y_weights_

# X loadings matrix of shape (K, A) = (50, 20).
pls.x_loadings_

# Y loadings matrix of shape (M, A) = (10, 20).
pls.y_loadings_

# X rotations matrix of shape (K, A) = (50, 20).
pls.x_rotations_

# Y rotations matrix of shape (M, A) = (10, 20). Lazily computed and cached on
# first access (it needs a pseudo-inverse that fit() does not otherwise pay for).
pls.y_rotations_

# Regression coefficients of shape (M, K) = (10, 50) and intercept of shape
# (M,) = (10,). Following scikit-learn, predict effectively centers X, so
# predict(X) == (X - X_mean) @ coef_.T + intercept_.
pls.coef_
pls.intercept_

# --- Transform to score space and reconstruct -------------------------------

# Project X onto the latent space. X scores have shape (N, A) = (100, 20).
x_scores = pls.transform(X)

# Passing Y as well returns both X scores and Y scores, each (N, A) = (100, 20).
x_scores, y_scores = pls.transform(X, Y)

# inverse_transform maps scores back to the original space: X_reconstructed has
# shape (N, K) = (100, 50) and Y_reconstructed has shape (N, M) = (100, 10). The
# round trip is exact only when n_components equals n_features / n_targets, so
# with A < K this is an approximate (dimensionality-reduced) reconstruction.
X_reconstructed = pls.inverse_transform(x_scores)
X_reconstructed, Y_reconstructed = pls.inverse_transform(x_scores, y_scores)

Examples

In examples, you will find:

Changelog

See CHANGELOG.md for version history and release notes.

Contribute

To contribute, please read the Contribution Guidelines.

References

  1. Dayal, B. S. and MacGregor, J. F. (1997). Improved PLS algorithms. Journal of Chemometrics, 11(1), 73-85.
  2. Alin, A. (2009). Comparison of PLS algorithms when the number of objects is much larger than the number of variables. Statistical Papers, 50, 711-720.
  3. Andersson, M. (2009). A comparison of nine PLS1 algorithms. Journal of Chemometrics, 23(10), 518-529.
  4. NumPy
  5. scikit-learn
  6. JAX
  7. Engstrøm, O.-C. G. and Jensen, M. H. (2025). Fast Partition-Based Cross-Validation With Centering and Scaling for $\mathbf{X}^\mathbf{T}\mathbf{X}$ and $\mathbf{X}^\mathbf{T}\mathbf{Y}$
  8. Becker and Ismail (2016). Accounting for sampling weights in PLS path modeling: Simulations and empirical examples. European Management Journal, 34(6), 606-617.

Funding

Metadata

Release files for ikpls 6.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for ikpls 6.2.0
File Size Uploaded Provenance Actions
ikpls-6.2.0.tar.gz 664.2 kB With provenance Details for ikpls-6.2.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for ikpls 6.2.0
File Interpreter ABI Platform Actions
ikpls-6.2.0-py3-none-any.whl Python 3 none any Details for ikpls-6.2.0-py3-none-any.whl

Total release size: 743.1 kB

Release files / ikpls-6.2.0.tar.gz

Download URL ikpls-6.2.0.tar.gz
Size 664.2 kB
Tags Source
SHA-256 checksum
How to use checksums
be00fab501f600c9428d45143c2923d4bea2c771fcb253a7ee1a8da96a97b703
BLAKE2b-256 checksum
How to use checksums
4a95c5341ae630af9c0c753b1254d4f8f2961587fef7c895feba033e41d9afdd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 31, 2026.

Transparency log

Release files / ikpls-6.2.0-py3-none-any.whl

Download URL ikpls-6.2.0-py3-none-any.whl
Size 78.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
da9a461e53c348c7f06701ca24339459403815d1c1b99a3a51b126138889fc74
BLAKE2b-256 checksum
How to use checksums
5c2f6e69b2a4372a5ad15473994e305ad12acbeb193bcc1b42c155b4f093af69
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 31, 2026.

Transparency log

Security for ikpls 6.2.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for ikpls-6.2.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 31, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

6.2.0 This release

2 release files Full provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page