blockperm
A block permutation test for cross-validated decoding. Use it when the labels follow recording blocks (for example, conditions presented in blocks of consecutive trials) and training and test trials can come from the same blocks.
block_permutation_test_score has the same call as scikit-learn's permutation_test_score, plus blocks=:
from blockperm import block_permutation_test_score
score, null_scores, p = block_permutation_test_score(
pipeline, X, y, blocks=block_id,
cv=KFold(5, shuffle=True, random_state=0), n_permutations=1000, random_state=0)
You can try it in the browser without installing anything: demo in Colab (about two minutes).
Why
Slow drift makes recording blocks distinguishable. When training and test trials share blocks, tests that permute single trials, or only the training labels, call labels with no information decodable far more often than 5%. Permuting the labels of whole blocks and refitting the whole pipeline in every permutation keeps the rate near 5% when conditions were assigned to blocks at random. The preprint has the measurements: https://doi.org/10.5281/zenodo.24012190
What it does
- Each permutation moves the labels of whole blocks, so training and test labels move together.
- The whole cross-validation is rerun in every permutation. Put every step fitted to the labels (scaling, feature or neuron selection, the model) in one scikit-learn
Pipeline. strata=permutes only within a run or a session.draw=takes your own generator of block labels, for example pseudosessions from the task's block generator.- With few blocks, every distinct arrangement is enumerated, and a warning gives the smallest p value you can get.
permutation_test_score(..., groups=blocks)does not do this: it shuffles within groups, and with one label per block nothing moves.
When it is valid
- The p value is exact when conditions were assigned to blocks at random, from the set the function permutes over (all blocks, or within
strata). - With a fixed block order, the test assumes that blocks are exchangeable. Drift that follows the order can break that.
Install
pip install blockperm
Python 3.12 or later, with numpy and scikit-learn. One CPU core is enough. The permutations run one after another (no n_jobs).
Documentation and citation
The tutorial, a MATLAB and Octave port, and the analyses behind the preprint are at https://github.com/jinchoi7651507/block-permutation-decoding.
If you use blockperm, please cite: Choi, D. (2026). Common decoding tests fail when training and test trials share recording blocks. Zenodo. https://doi.org/10.5281/zenodo.24012190
License: MIT.
Metadata
Release files for blockperm 0.1.1
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 |
|---|---|---|---|---|
| blockperm-0.1.1.tar.gz | 10.2 kB | Without provenance | Details for blockperm-0.1.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| blockperm-0.1.1-py3-none-any.whl | Python 3 | none | any | Details for blockperm-0.1.1-py3-none-any.whl |
Total release size: 17.6 kB
Release files / blockperm-0.1.1.tar.gz
| Download URL | blockperm-0.1.1.tar.gz |
|---|---|
| Size | 10.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
89c54d91ba8c239462417c5aad607e72dfbdf753fd53cc513237c88781626014
|
|
BLAKE2b-256 checksum How to use checksums |
935633973d9388da814ebb99af7fa84585458322fba856ff611a1b5f9a2988e5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.12.3
|
Release files / blockperm-0.1.1-py3-none-any.whl
| Download URL | blockperm-0.1.1-py3-none-any.whl |
|---|---|
| Size | 7.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
6ea4de584bdc0dbcb07405cbb65b6ebe50e6e560b5fe0ccfbb8426edb045272f
|
|
BLAKE2b-256 checksum How to use checksums |
ab35d2ba5af71e16fb42a1c25c1979501e2976b9be5fc60b03ab122e7077458f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.12.3
|
Security for blockperm 0.1.1
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.