Skip to main content

pls4all

pls4all is the slim, PLS-only subset of nirs4all-methods — a thin Python binding over the portable libn4m C ABI (a C++17 PLS / NIRS engine). The wheel bundles the libn4m shared library, so pip install pls4all is self-contained; no separate native build is required. For the full method surface (preprocessing, selectors, diagnostics, augmenters, …) install the nirs4all-methods package instead and import it as n4m — both load the same libn4m.

The binding loads libn4m with ctypes.CDLL (so the GIL is released during native calls) and exposes:

  • version() / abi_version() introspection,
  • a Pythonic Context and Config (RAII lifecycle wrappers),
  • the PLS fit/predict surface and a scikit-learn-compatible pls4all.sklearn.PLSRegression (and the other PLS-family estimators),
  • a typed Pls4allError raised on any non-OK status, carrying the context's last_error message.

Quick start

import numpy as np
import pls4all
from pls4all.sklearn import PLSRegression

print(pls4all.version())      # e.g. "1.2.1+abi.2.17.0"
print(pls4all.abi_version())  # (2, 17, 0)

rng = np.random.default_rng(0)
X = rng.standard_normal((40, 12))
y = X @ rng.standard_normal(12)

model = PLSRegression(n_components=5).fit(X, y)
print(model.predict(X).shape)  # (40,)

Low-level lifecycle, if you need it:

with pls4all.Context() as ctx, pls4all.Config() as cfg:
    cfg.algorithm = pls4all.Algorithm.PLS_REGRESSION
    cfg.solver = pls4all.Solver.SIMPLS
    cfg.n_components = 5
    # ... drive a fit through the C ABI ...

scikit-learn is an optional dependency (only pls4all.sklearn needs it); the core import pls4all works with NumPy alone.

Verified affine-model migration

pls4all.export_linear_predictor_n4mm(...) is the public, PREDICT-only migration boundary for a converter that has already verified a source model's affine equation. It accepts finite, row-major coefficients with shape (n_features, n_targets) and a target-length intercept, then returns a raw N4MM payload. It neither reads pickle/joblib data nor retrains a model.

from pls4all import export_linear_predictor_n4mm

payload = export_linear_predictor_n4mm(
    coefficients=[[0.5], [-1.0]],
    intercept=[0.25],
    source_training_samples=120,
)
assert payload[:4] == b"N4MM"

The resulting imported-linear-predictor model supports native prediction only; it deliberately does not claim to reconstruct a source PLS latent transform. Callers remain responsible for attesting that the source model is exactly intercept + X @ coefficients before conversion.

Pure-native estimator selection in the full package

The full nirs4all-methods distribution (imported as n4m) exposes the native single-level finetuning driver. It is not part of the slim pls4all namespace. Build the validation plan and search space through public owning objects:

import numpy as np

from n4m.model_selection import (
    Algorithm,
    Metric,
    Sampler,
    SearchSpace,
    ValidationPlan,
    finetune_estimator,
)

rng = np.random.default_rng(42)
X = rng.normal(size=(60, 12))
y = X @ rng.normal(size=12) + rng.normal(scale=0.02, size=60)
fold_ids = np.arange(X.shape[0], dtype=np.int32) % 5

with ValidationPlan.from_fold_ids(fold_ids) as plan:
    with SearchSpace() as space:
        space.add_int("n_components", 1, 10)
        result = finetune_estimator(
            Algorithm.PLS_REGRESSION,
            X,
            y,
            plan,
            space,
            n_trials=30,
            sampler=Sampler.TPE,
            metric=Metric.RMSE,
            seed=42,
            timeout_seconds=20.0,
        )

print(result.best_params)       # for example: {"n_components": 6}
print(result.best_score)
print(result.timed_out)         # True only for a successful partial timeout
print(len(result.trials))       # owning completed/failed trial snapshots

The eligible algorithms are PLS_REGRESSION, PLS_CANONICAL, PLS_SVD, OPLS, SPARSE_PLS and PCR. The five non-sparse routes require the exact keyword n_components, a non-log integer axis. SPARSE_PLS accepts any non-empty subset of n_components and sparsity_lambda; omitted axes retain the native defaults 2 and 0.0. sparsity_lambda must stay in [0, 1) and may be declared with space.add_float(..., log=True) when low > 0.

This call selects a configuration and returns an owning trace; it does not fit a final estimator on all rows. A timeout before any completion raises N4MError with CANCELLED. A later timeout returns the best partial result with result.timed_out is True and fewer trials than result.requested_trials. See docs/methods/optimization.md for the exact schema, status and validation-plan contracts.

Relation to nirs4all conformal learning and robustness

The Python bindings are thin translation layers over the libn4m C ABI. They expose native kernels, scikit-learn-compatible PLS estimators and the single-estimator finetune_estimator(...) selection trace, but they do not own the higher-level nirs4all statistical lifecycle.

Use nirs4all.run(tuning=...) when the workflow needs final winner projection, workspace persistence, .n4a packaging, optional nirs4all.calibrate() / predict_calibrated() semantics, CalibratedRunResult, or nirs4all.robustness() / RobustnessReport artifacts. Those guarantees and invalidation reasons are produced by nirs4all, not by n4m or pls4all.

Binding consumers must not reimplement tuning/conformal/robustness guarantees from raw native predictions. A UI, Studio panel or alternate language binding that wants to display conformal intervals or robustness summaries should consume the public nirs4all artifact/schema surfaces instead of inferring guarantees locally from finetune_estimator(...) or PLSRegression.predict(...).

Loading libn4m

The bundled wheel ships libn4m inside pls4all/lib/, found automatically. For development against a local build the loader searches, in order:

  1. $PLS4ALL_LIB_PATH — explicit path to libn4m for this package,
  2. $N4M_LIB_PATH — shared libn4m override honoured by both pls4all and n4m,
  3. pls4all/lib/libn4m* next to the installed package (wheel layout),
  4. <repo-root>/build/dev-release/cpp/src/libn4m* (developer convenience),
  5. the standard system search path (LD_LIBRARY_PATH, macOS rpath, Windows PATH).

Building libn4m from source (developers)

cmake --preset dev-release
cmake --build --preset dev-release --parallel

This produces build/dev-release/cpp/src/libn4m.so (.dylib / .dll on macOS / Windows), which the loader rules above pick up.

See https://github.com/GBeurier/nirs4all-methods for the full project.

Metadata

Release files for pls4all 1.3.2

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

Source distribution (sdist)

Source distribution for pls4all 1.3.2
File Size Uploaded
pls4all-1.3.2.tar.gz 201.3 kB Details

Built distributions (wheels)

Table of built distributions (wheels) for pls4all 1.3.2
File
pls4all-1.3.2-py3-none-win_amd64.whl Python 3 none Windows x86-64 Details
pls4all-1.3.2-py3-none-musllinux_1_2_x86_64.whl Python 3 none Linux musl 1.2+ x86-64 Details
pls4all-1.3.2-py3-none-musllinux_1_2_aarch64.whl Python 3 none Linux musl 1.2+ ARM64 Details
pls4all-1.3.2-py3-none-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl Python 3 none Linux glibc 2.28+ x86-64, Linux glibc 2.24+ x86-64 Details
pls4all-1.3.2-py3-none-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl Python 3 none Linux glibc 2.28+ ARM64, Linux glibc 2.24+ ARM64 Details
pls4all-1.3.2-py3-none-macosx_11_0_universal2.whl Python 3 none macOS 11.0+ universal2 (ARM64, x86-64) Details

Total release size: 36.9 MB

Release files / pls4all-1.3.2.tar.gz

Download URL pls4all-1.3.2.tar.gz
Size 201.3 kB
Tags Source
SHA-256 checksum
How to use checksums
e390fb9880a464e81c52713b5c537d7af5bb47f9908db859e13e265eb9887610
BLAKE2b-256 checksum
How to use checksums
5af5e98642f8ff1b9932c2889bcfe49cfef9fcfc17375b47533db70017e7bfa0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 4, 2026.

Transparency log

Release files / pls4all-1.3.2-py3-none-win_amd64.whl

Download URL pls4all-1.3.2-py3-none-win_amd64.whl
Size 1.8 MB
Tags Python 3 Windows x86-64
SHA-256 checksum
How to use checksums
6a8587973cd2c68bcdd253b31daa6770b3bdf4e72dbbf0c35b8108d97f5bec65
BLAKE2b-256 checksum
How to use checksums
aae5acbfe0bb5f687f0a0202d9b7923f2d83ea6f5281070400057049d5aba95d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 4, 2026.

Transparency log

Release files / pls4all-1.3.2-py3-none-musllinux_1_2_x86_64.whl

Download URL pls4all-1.3.2-py3-none-musllinux_1_2_x86_64.whl
Size 6.8 MB
Tags Linux musl 1.2+ x86-64 Python 3
SHA-256 checksum
How to use checksums
3b2fb0d65a9dc93d7e095102de05652751fe413475b2cd149141e04ebfde7863
BLAKE2b-256 checksum
How to use checksums
3938020121abd9e27f72a11c215bc469d3839cc53eb1f4568711fd835a702450
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 4, 2026.

Transparency log

Release files / pls4all-1.3.2-py3-none-musllinux_1_2_aarch64.whl

Download URL pls4all-1.3.2-py3-none-musllinux_1_2_aarch64.whl
Size 6.1 MB
Tags Linux musl 1.2+ ARM64 Python 3
SHA-256 checksum
How to use checksums
c3a972fa4c6724117cc4dfe424ea9b72e70f91ded6c062297287e8695056cad2
BLAKE2b-256 checksum
How to use checksums
93ad00bc615f03e5d8c5e96b7f33a6ccd7375ac9584af3732de5a0f9ac58dcfa
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 4, 2026.

Transparency log

Release files / pls4all-1.3.2-py3-none-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl

Download URL pls4all-1.3.2-py3-none-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Size 5.8 MB
Tags Linux glibc 2.24+ x86-64 Linux glibc 2.28+ x86-64 Python 3
SHA-256 checksum
How to use checksums
626fd5a9decfebcbe3c23a862e7a729259578100eeb119f766d802b35e73e1df
BLAKE2b-256 checksum
How to use checksums
34af5979445c507d4b60bf543dbccc18e110ae8440f81bd2d6a553df9a70bf3e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 4, 2026.

Transparency log

Release files / pls4all-1.3.2-py3-none-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl

Download URL pls4all-1.3.2-py3-none-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl
Size 5.1 MB
Tags Linux glibc 2.24+ ARM64 Linux glibc 2.28+ ARM64 Python 3
SHA-256 checksum
How to use checksums
85455f95d425f56bf278aec1140b0133421ec579b612eb10cb351543434bc874
BLAKE2b-256 checksum
How to use checksums
b98b6e4fe6f6c2a5e8600cd1a9394b566bd867d8139750e767133bc29757e2ed
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 4, 2026.

Transparency log

Release files / pls4all-1.3.2-py3-none-macosx_11_0_universal2.whl

Download URL pls4all-1.3.2-py3-none-macosx_11_0_universal2.whl
Size 11.2 MB
Tags Python 3 macOS 11.0+ universal2 (ARM64, x86-64)
SHA-256 checksum
How to use checksums
0872af3edb2b5cbde274191d10800ba71bb177ae87c022aae67e695a155b9556
BLAKE2b-256 checksum
How to use checksums
7c9f8c48f7acd2a9b4850ebfce12b67201617f254fa6ece5843c804805b67ef2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 4, 2026.

Transparency log

Release history Release notifications | RSS feed

1.3.6

7 release files

1.3.4

7 release files

1.3.3

7 release files

This release

1.3.2 This release

7 release files

1.3.1

7 release files

1.2.1

7 release files

1.2.0

7 release files

1.1.1

7 release files

1.1.0

7 release files

1.0.21

7 release files

1.0.20

7 release files

1.0.13

7 release files

1.0.12

7 release files

1.0.11

7 release files

1.0.10

7 release files

1.0.9

7 release files

1.0.8

7 release files

1.0.7

7 release files

1.0.6

7 release files

1.0.5

7 release files

1.0.2

7 release files

1.0.1

7 release files

0.99.0

7 release files

0.97.3

7 release files

0.97.2

7 release files

0.97.1

7 release files

0.97.0

7 release files

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