Skip to main content

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.10 or later (tested on 3.10 to 3.13), 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.3

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

Source distribution (sdist)

Source distribution for blockperm 0.1.3
File Size Uploaded Provenance Actions
blockperm-0.1.3.tar.gz 7.1 kB Without provenance Details for blockperm-0.1.3.tar.gz

Built distribution (wheel)

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

Total release size: 14.6 kB

Release files / blockperm-0.1.3.tar.gz

Download URL blockperm-0.1.3.tar.gz
Size 7.1 kB
Tags Source
SHA-256 checksum
How to use checksums
bbdc3e3627f985480f12c8c86e524224e2415a5aabc0357edcebb962d4cbcd57
BLAKE2b-256 checksum
How to use checksums
44fec9c58d6a166ab55588981be3f5c9a258ccc7b3d9a61ab35a5ecd3fe89cf3
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.3-py3-none-any.whl

Download URL blockperm-0.1.3-py3-none-any.whl
Size 7.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
e55fe68bffcad190c5094aaca9f9114a2444b9636cbbc9ccf572f71bf3847e89
BLAKE2b-256 checksum
How to use checksums
02abe75462955d391b3b3825f21d5acafd78d6ba516abadfbae9fa9661c9790b
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.3

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