Skip to main content

Procrustes cross-validation for Python

Package prcv implements Procrustes cross-validation in Python language.

Last version of the package (1.2.2) was released in November, 2026. It fixes several bugs: columns with constant values were not handled correctly during scaling, a response given as a one-dimensional array was not accepted, PLS could fail when the number of components had to be reduced, and rounding errors could flip the signs of local loadings. NumPy and SciPy are now installed automatically as dependencies. See details in the overall project description.

Getting started

You can install the package directly from PyPI by running pip install prcv. If you already have the package installed and want to upgrade it to the newest version use: pip install prcv --upgrade

There are three main functions in the package:

  • pcvpca() is implementation of PCV for PCA/SIMCA models.

  • pcvpcr() is implementation of PCV for PCR models.

  • pcvpls() is implementation of PCV for PLS models.

All three functions return PV-set generated with given parameters. The PV-set has the same size as the calibration set. In case of regression (PCR or PLS) PV-set is generated only for predictors (X), the response values for PV-set are the same as for the calibration set.

The last two functions return the PV-set and an additional outcome, D, which is a matrix (2D Numpy array) containing scaling factors ($c_k/c$), for each segment and each component. See all details in the paper.

Below are examples of the function syntax with main parameters:

from prcv.methods import pcvpca, pcvpcr, pcvpls

# set cross-validation settings — common for all methods above
cv = {'type': 'ven', 'nseg': 4}

# for PCA/SIMCA models
Xpv = pcvpca(X, ncomp = 20, center = True, scale = False, cv = cv)

# for PCR models
Xpv, D = pcvpcr(X, Y, ncomp = 20, center = True, scale = False, cv = cv)

# for PLS models
Xpv, D = pcvpls(X, Y, ncomp = 20, center = True, scale = False, cv = cv)

Here X is a matrix with predictors for your calibration set (2D Numpy array). In case of regression model you also need to provide an array with response values for the training set, Y. The method generates PV-set only for predictors, the response values for the calibration set and for the PV-set are the same.

Parameter ncomp is a number of principal components in case of PCA/PCR models or number of latent variables in case of PLS based method. Number of components must be large enough, larger than the expected optimal number. In case of PCA use components which explain at least 99% of the data.

Parameters center and scale define if columns of X and Y should be mean centered and/or standardized. By default center = True and scale = False. Regardless which settings you use, the resulted PV-set will be in original units (uncentered and unstandardized), so you can compare it directly with the calibration set.

Finally, parameter cv defines how to split the rows of the training set. The split is similar to cross-validation splits, as PCV is based on cross-validation resampling. This parameter can have the following values:

  • A dictionary with 2 field: 'type' and 'nseg'. In this case 'type' defines the way to make the splits. You can select one of the following: 'loo' for leave-one-out, 'rand' for random splits or 'ven' for Venetian blinds (systematic) splits. The second field, 'nseg', should be a number of segments for splitting the rows into. For example, cv = {'type': 'ven', 'nseg': 4}, shown in the code examples above, tells PCV to use Venetian blinds splits with 4 segments.

  • A vector with integer numbers, e.g. cv = np.array([1, 2, 3, 1, 2, 3, 1, 2, 3], dtype = 'int'). In this case number of values in this vector must be the same as number of rows in the training set. The values specify which segment a particular row will belong to. For the example shown here, it is assumed that you have 9 rows in the calibration set, which will be split into 3 segments. The first segment will consist of measurements from rows 1, 4 and 7.

As it is written above there is also additional parameter, cvscope, which can have one of the two values, 'global' or 'local'. The default value is 'global', if you want to try the local scope, just add this parameter when you call one of the functions, like shown below (in this example some of the arguments are skipped for simplicity):

# PCV for PLS models with local CV scope
Xpv, D = pcvpls(X, Y, ncomp = 20,  cv = {'type': 'ven', 'nseg': 4}, cvscope = 'local')

Directory demo, which is available from GitHub repository, contains several files with dataset and demo code. Thus file corn.csv contains Corn dataset used in the paper in Coma Separated Values format. File demo.py contains script with demo code and file demo.ipynb contains the same code but made as a Jupyter notebook. File misc.py contains several helper functions for the demo code, which are used in both the script and the notebook.

Download all files and make sure all files are located in the same folder in order to run the code.

The package code will be improved and extended gradually. If you found a bug please report using issues or send an email.

Metadata

Release files for prcv 1.2.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 prcv 1.2.2
File Size Uploaded Provenance Actions
prcv-1.2.2.tar.gz 758.2 kB Without provenance Details for prcv-1.2.2.tar.gz

Built distribution (wheel)

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

Total release size: 768.5 kB

Release files / prcv-1.2.2.tar.gz

Download URL prcv-1.2.2.tar.gz
Size 758.2 kB
Tags Source
SHA-256 checksum
How to use checksums
999e66e73dd13cdd88c8104fbc63d6cab703af2af503e7fa1ddf969da79265a0
BLAKE2b-256 checksum
How to use checksums
d5ee5a08b33c155e0e0dd1236fa4bd3dbaaa813c7f72a9f3fdd91276c2113ffc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.15.2

Release files / prcv-1.2.2-py3-none-any.whl

Download URL prcv-1.2.2-py3-none-any.whl
Size 10.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
6fc71e56e87c924982d0224391a008965129a5a48d5acc625cb93d29ea38cfde
BLAKE2b-256 checksum
How to use checksums
281749893953cf44595614677876f1d919c01a0c25745994774cb4cd0f7af9ad
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.15.2

Security for prcv 1.2.2

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.

No provenance found

None of the files in this release were uploaded with provenance metadata.

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.

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