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.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.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 blockperm 0.1.2
File Size Uploaded Provenance Actions
blockperm-0.1.2.tar.gz 10.2 kB Without provenance Details for blockperm-0.1.2.tar.gz

Built distribution (wheel)

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

Total release size: 17.6 kB

Release files / blockperm-0.1.2.tar.gz

Download URL blockperm-0.1.2.tar.gz
Size 10.2 kB
Tags Source
SHA-256 checksum
How to use checksums
1b94af8d3fa70bf27709359c53cc971cfff291cf3d17b928cbd9a4811c63691e
BLAKE2b-256 checksum
How to use checksums
5962fe967f5567361625cf7bc1836e282d2884865919fb4a13c398793083c133
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.2-py3-none-any.whl

Download URL blockperm-0.1.2-py3-none-any.whl
Size 7.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
2b4f4324e29ce36604a3a481ebb6028f518d0a845a903e78f32ba83e329d281f
BLAKE2b-256 checksum
How to use checksums
688b96adb064def71aa060e73053b396bef6587e7a1abcdbcf3b02edd35a9a61
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.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