Skip to main content

attp (Adaptive Train Test Partitioner)

Cluster-stratified train/test splitting on an LDA-reduced feature space (S-ATTP).

Instead of stratifying on the class label alone, sattp also stratifies on where a row sits in feature space, so the test set covers the same sub-populations as the train set.

How it works

  1. Reduce the features with LDA, using the fewest components that reach 85% of the explained variance (configurable).
  2. For each candidate cluster count, run K-Means once on the LDA components and reuse those clusters across candidate train fractions (MiniBatchKMeans above 50,000 rows).
  3. Build strata from class × cluster and do a stratified split. Strata with a single member can't be split, so those rows always go to the train set.
  4. Score a classifier on every (train fraction, n_clusters) pair and return the split with the best test score.

Process Flow Diagram

process flow diagram

Install

pip install i-attp

Or install directly from GitHub:

pip install git+https://github.com/Jabualani/ATTP.git

For development:

git clone https://github.com/Jabualani/ATTP.git
cd ATTP
pip install -e ".[dev]"
pytest

Usage

from attp import sattp_split

result = sattp_split(
    X, y,
    splits=[0.7, 0.75, 0.8],   # candidate train fractions
    min_clusters=2,
    max_clusters=10,
)

X_train, y_train, X_test, y_test = result      # unpacks like a 4-tuple
print(result.best_split, result.best_n_clusters, result.n_lda_components)
print(result.metrics.head())                    # every candidate, best first

Row labels of the original X/y are preserved in the outputs.

Useful options: model= (any scikit-learn classifier used for scoring; defaults to LDA), scoring= (custom (fitted_model, X, y) -> float), variance_threshold=, random_state=, verbose=True to print progress and the selected split. Set DR_Comps_Min= and DR_Comps_Max= to choose the LDA component range.

Original function signature

S_ATTP keeps the original call signature for existing code:

from attp import S_ATTP

X_tr, y_tr, X_te, y_te = S_ATTP(
    X_df, y_df, "target_col", [0.7, 0.8], 2, 10, 1, 3, None, "frames", False, False
)

return_type="indices" returns (train_index, test_index), and return_split_metadata=True appends the metrics DataFrame. If no valid split exists it returns Nones, like the original.

Caveats

  • LDA is fitted on the whole dataset (using all labels) before splitting, and the winning split is chosen by its test score. Both make the reported test score optimistic. Treat it as a way to build a representative split, not as an unbiased performance estimate.
  • Features must be numeric with no missing values.

License

MIT

Metadata

Release files for i-attp 0.1.1

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

Source distribution (sdist)

Source distribution for i-attp 0.1.1
File Size Uploaded
i_attp-0.1.1.tar.gz 116.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for i-attp 0.1.1
File Interpreter ABI Platform
i_attp-0.1.1-py3-none-any.whl Python 3 none any Details

Total release size: 122.7 kB

Release files / i_attp-0.1.1.tar.gz

Download URL i_attp-0.1.1.tar.gz
Size 116.1 kB
Tags Source
SHA-256 checksum
How to use checksums
fcf6756d4054deddaacef2c4023739f911e60e6a7a9bc21eeefb6448fb2a5c02
BLAKE2b-256 checksum
How to use checksums
0698841c7a7c9f4d9a311ec96e377cbef8684060f38da9324fce96275f98baf5
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 15, 2026.

Transparency log

Release files / i_attp-0.1.1-py3-none-any.whl

Download URL i_attp-0.1.1-py3-none-any.whl
Size 6.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
605a24969dd83535a9b52a62d12411d417c4c54870892b1e91c49221fd873ae5
BLAKE2b-256 checksum
How to use checksums
81664a1bacc6ffb330a850d52ca4dc4eddab9c0574a52fc0af36ddc29d100ce3
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 15, 2026.

Transparency log

Release history Release notifications | RSS feed

0.2.3

2 release files

0.2.2

2 release files

0.2.1

2 release files

0.2.0

2 release files

0.1.2

2 release files

This release

0.1.1 This release

2 release files

0.1.0

2 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