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
ContextandConfig(RAII lifecycle wrappers), - the PLS fit/predict surface and a scikit-learn-compatible
pls4all.sklearn.PLSRegression(and the other PLS-family estimators), - a typed
Pls4allErrorraised on any non-OK status, carrying the context'slast_errormessage.
Quick start
import numpy as np
import pls4all
from pls4all.sklearn import PLSRegression
print(pls4all.version()) # e.g. "1.3.18+abi.2.23.0"
print(pls4all.abi_version()) # (2, 23, 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.
Explainability in the full package
n4m.explain (full nirs4all-methods distribution, not the slim pls4all
namespace) wraps the native n4m/explain.h attribution kernels. All numerics
run in libn4m; the binding only marshals arrays and drives the native ask/tell
session, so any Python predictor works:
import numpy as np
from n4m import explain as ex
# X and background live in the feature space the predictor consumes, e.g. raw
# spectra of a complete fitted pipeline.
groups, n_groups = ex.groups_fixed_width(X.shape[1], 16) # optional grouping
result = ex.explain(
pipeline.predict, # receives C-contiguous float64 (rows, n_features)
X,
background=background,
feature_group=groups,
n_groups=n_groups,
method="permutation_shap", # exact_shap | permutation_shap | kernel_shap | lime | occlusion
baseline="background", # background | mean | interpolate
n_permutations=10,
seed=0,
progress=lambda done, total: print(f"{done}/{total}"),
)
result.attributions # (n_rows, n_groups, n_outputs)
result.expected, result.predictions
result.exactness, result.additivity_max_abs_error
mean_abs, mean_signed = ex.summarize(result.attributions, output_index=0)
predict_batch returns (rows,) or (rows, n_outputs) finite predictions in
whatever output space the host chose (target units, a class probability, a
decision score); the binding never relabels it. n_outputs is inferred from
one probe row when omitted.
| Kind | exactness |
Additive | group_aggregation |
|---|---|---|---|
exact_shap (groups <= 16) |
exact |
yes | group_game |
permutation_shap (antithetic; std_error = Monte-Carlo SE) |
sampled |
yes | group_game |
kernel_shap |
sampled, exact when the budget covers all 2^G - 2 coalitions |
yes | group_game |
lime |
surrogate |
no | group_game |
occlusion |
perturbation |
no | group_game |
linear_shap(X, coefficients, reference=..., intercept=...) |
exact (interventional) |
yes | none, or group_game with groups |
tree_shap(X, TreeEnsemble(...)) (path-dependent) |
exact |
yes | none, or sum_of_feature_values with groups |
TreeEnsemble is a generic flat layout (concatenated nodes, per-tree
offsets, local child indices, cover and leaf values, decision_type 0 for
x <= threshold or 1 for x < threshold, optional base_offset and
tree_scale). Converting scikit-learn, XGBoost or LightGBM models into it is
the host's job (the nirs4all SDK). groups_from_ranges(n_features, ranges)
turns half-open feature-index ranges (for example chemical bands already
mapped to indices) into a partition and reports the source range of each
group (-1 for uncovered runs). settings uses the snake_case keys of the
nirs4all.explanation.v1 envelope; hosts add axis, output and sample-index
metadata. bench/explain/bench_explain.py times every explainer over spectral
widths, group widths and background sizes.
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:
$PLS4ALL_LIB_PATH— explicit path tolibn4mfor this package,$N4M_LIB_PATH— sharedlibn4moverride honoured by bothpls4allandn4m,pls4all/lib/libn4m*next to the installed package (wheel layout),<repo-root>/build/dev-release/cpp/src/libn4m*(developer convenience),- the standard system search path (
LD_LIBRARY_PATH, macOS rpath, WindowsPATH).
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.
SNV scalar contract
n4m.transform.scatter.SNV and generated n4m.roles.SNV share strict private
scalar admission: flags are Python/NumPy booleans; ddof is a nonboolean
Integral with operator.index in [0, INT32_MAX]. NumPy integer scalars and
IntEnum are admitted; timedelta64, strings, fractional/whole floats and booleans
as ddof are refused before native parameter setters. Legacy SNV revalidates
current attributes before fit/transform, recreates changed handles, and applies
set_params atomically, including without sklearn. The unused unexported
n4m._impl.native.snv function is removed; use the public SNV classes.
When scaling nonempty data, ddof < n_features is required by libn4m before
output writes. Centering-only/no-op accepts any valid nonnegative ddof;
uncentered scaling uses SD about the row mean. Valid constant rows retain
their zero-SD fallback. pls4all accepts canonical Solver tokens including
kernel_algorithm and keeps kernel and existing aliases/defaults unchanged.
Metadata
Release files for pls4all 1.3.18
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| pls4all-1.3.18.tar.gz | 309.0 kB | With provenance | Details for pls4all-1.3.18.tar.gz |
Built distributions (wheels)
Total release size: 39.0 MB
Release files / pls4all-1.3.18.tar.gz
| Download URL | pls4all-1.3.18.tar.gz |
|---|---|
| Size | 309.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
0ce7d8fd1c7a41bb0e42c5f4a63d94c318970ff1928d7b6e4ae2d04c5a8ac726
|
|
BLAKE2b-256 checksum How to use checksums |
6419bf7cbe1cf027895611db99d98b54ec11c60566240db2512c9b477b5fc389
|
| 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 Nov 16, 2026.
Transparency logRelease files / pls4all-1.3.18-py3-none-win_amd64.whl
| Download URL | pls4all-1.3.18-py3-none-win_amd64.whl |
|---|---|
| Size | 2.1 MB |
| Tags | Python 3 Windows x86-64 |
|
SHA-256 checksum How to use checksums |
92468329dd582135564e266b51000b0d6abfb4fcf5810b870fbcedad8983f1e5
|
|
BLAKE2b-256 checksum How to use checksums |
702bb7c3e17fe8582c3b355654a36ceb8b8406c8c06614737d5c5fad4c978e97
|
| 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 Nov 16, 2026.
Transparency logRelease files / pls4all-1.3.18-py3-none-musllinux_1_2_x86_64.whl
| Download URL | pls4all-1.3.18-py3-none-musllinux_1_2_x86_64.whl |
|---|---|
| Size | 7.3 MB |
| Tags | Linux musl 1.2+ x86-64 Python 3 |
|
SHA-256 checksum How to use checksums |
d2e43cb0c7d770975274975636bdcf82a7c945b1bdc1f789ab7630f593f6a6a1
|
|
BLAKE2b-256 checksum How to use checksums |
e4d919270f59f06c7e5427da1ea6843d1fe0e1663709e85194b2f4bd0c815ca1
|
| 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 Nov 16, 2026.
Transparency logRelease files / pls4all-1.3.18-py3-none-musllinux_1_2_aarch64.whl
| Download URL | pls4all-1.3.18-py3-none-musllinux_1_2_aarch64.whl |
|---|---|
| Size | 6.5 MB |
| Tags | Linux musl 1.2+ ARM64 Python 3 |
|
SHA-256 checksum How to use checksums |
885a8831ba0bd954b6dd90a5522c2c1456a12cde9c7a27a0ebd23c0e70ccf4d9
|
|
BLAKE2b-256 checksum How to use checksums |
6b1178e2b40901de29128b121054e563d066472b61bd618696b928cd9270d509
|
| 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 Nov 16, 2026.
Transparency logRelease files / pls4all-1.3.18-py3-none-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
| Download URL | pls4all-1.3.18-py3-none-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl |
|---|---|
| Size | 6.3 MB |
| Tags | Linux glibc 2.24+ x86-64 Linux glibc 2.28+ x86-64 Python 3 |
|
SHA-256 checksum How to use checksums |
4ef7accac1a4ed53810f94d7f5b4fdaffb1b9ba4ffc3921fa0a1890117cfb62d
|
|
BLAKE2b-256 checksum How to use checksums |
611a34d6b6ee4a293265973df45b66970d49ca544f6466d7918ee86dc78ecdd6
|
| 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 Nov 16, 2026.
Transparency logRelease files / pls4all-1.3.18-py3-none-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl
| Download URL | pls4all-1.3.18-py3-none-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl |
|---|---|
| Size | 5.5 MB |
| Tags | Linux glibc 2.24+ ARM64 Linux glibc 2.28+ ARM64 Python 3 |
|
SHA-256 checksum How to use checksums |
0699962ade6f30831836001ca22747b0fd45ee3653fa51109628d778d4239de8
|
|
BLAKE2b-256 checksum How to use checksums |
e9584e663c9b98bc24467273bf203ee00a394d520162b87f8788624cba4e5242
|
| 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 Nov 16, 2026.
Transparency logRelease files / pls4all-1.3.18-py3-none-macosx_11_0_universal2.whl
| Download URL | pls4all-1.3.18-py3-none-macosx_11_0_universal2.whl |
|---|---|
| Size | 11.1 MB |
| Tags | Python 3 macOS 11.0+ universal2 (ARM64, x86-64) |
|
SHA-256 checksum How to use checksums |
51fea2f3fbf1bbaf8356f40dc88940e8bef0177779283e03e388b9bca88e878b
|
|
BLAKE2b-256 checksum How to use checksums |
81c1c89fa12ff5632e0c58b8e9558ac75d2cc6d243124bf04faa14d8782047d7
|
| 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 Nov 16, 2026.
Transparency logSecurity for pls4all 1.3.18
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
All 7 files in this release have been uploaded with provenance metadata.
Attestation for pls4all-1.3.18.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 Nov 16, 2026.
Transparency logA 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.