pymaxtwin
Python implementation of MaxTwin (Joseph and Cho, 2026), a deterministic train/test split that preserves the distribution of the data while keeping testing points away from training points.
Twenty testing points (red) chosen from 100 by maximum separation, SPlit, and MaxTwin.
Installation
pip install pymaxtwin
Usage
import numpy as np
from pymaxtwin import maxtwin
X = np.random.rand(100, 5)
Y = np.sin(X[:, 0]) + X[:, 1] ** 2
test_idx = maxtwin(X, Y, splitratio=0.2) # sorted, 0-indexed
train_idx = np.setdiff1d(np.arange(len(X)), test_idx)
| Argument | Default | Description |
|---|---|---|
splitratio |
— | Test fraction; must be 1/r for an integer r >= 2 (0.5, 0.25, 0.2, ...) |
initialization |
True |
Start twinning from the point closest to the centroid |
standardization |
True |
Standardize the augmented data before twinning |
initialmaxtwin() runs the first step only, without the separation improvement.
Results
Paired data: the improved algorithm assigns close pairs entirely to training or testing.
MaxTwin keeps the energy distance low and the separation distance high on both unpaired and paired data.
R package
The same method is available on CRAN as maxtwin.
Citation
@article{joseph2026maxtwin,
author = {Joseph, V. Roshan and Cho, Youngseo},
title = {A Robust Deterministic Data Splitting Method for Model Validation},
journal = {Journal of Computational and Graphical Statistics},
year = {2026},
doi = {10.1080/10618600.2026.2754089}
}
License
GPL-3.0-or-later
Metadata
Release files for pymaxtwin 0.1.0
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 |
|---|---|---|---|---|
| pymaxtwin-0.1.0.tar.gz | 19.4 kB | With provenance | Details for pymaxtwin-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| pymaxtwin-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for pymaxtwin-0.1.0-py3-none-any.whl |
Total release size: 37.6 kB
Release files / pymaxtwin-0.1.0.tar.gz
| Download URL | pymaxtwin-0.1.0.tar.gz |
|---|---|
| Size | 19.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
d856d9bb7b7cbbecfd84ff2621f266a80284e4b67e5c1db569da657d38e91234
|
|
BLAKE2b-256 checksum How to use checksums |
9f485d7b7e29054ebf5acaf7f4974849fe7c58a37a5cdf3285ebe45e7512505e
|
| 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 10, 2026.
Transparency logRelease files / pymaxtwin-0.1.0-py3-none-any.whl
| Download URL | pymaxtwin-0.1.0-py3-none-any.whl |
|---|---|
| Size | 18.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
8bc22b36e52704408260dd162ed0099d003e9a98dad20b526f30856d15f61208
|
|
BLAKE2b-256 checksum How to use checksums |
0b361db0602ccaaafe51f78d246d8dc2406c88f8a9d703cfcdd2b13c647b0ffd
|
| 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 10, 2026.
Transparency logSecurity for pymaxtwin 0.1.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.
Attestation for pymaxtwin-0.1.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 Nov 10, 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.