Skip to main content

PyPlasmode

PyPlasmode tests prediction and feature selection against a known signal. It combines your feature data with simulated outcomes to measure how accurately a model predicts them and how well it identifies the generating features used to produce them.

A plasmode uses observed measurements to maintain realistic feature relationships while you control how the outcome is generated. The library was built for biomarker benchmarking and accepts any numeric matrix of observations and named features, including the synthetic matrices below.

You can integrate it with your existing modelling workflow. Generate a dataset, fit and tune your models, then evaluate their predictions, feature rankings, or selected panels.

From observed measurements to simulated outcomes, model predictions and feature recovery

The visual gallery shows signal structures, recovery among correlated features and the five outcome families. The feature-selection tutorial follows a complete example from correlated measurements through model fitting, attribution and recovery above chance.

Installation

Requires Python 3.12-3.15. Install from PyPI:

python -m pip install pyplasmode

The runtime dependencies are NumPy, SciPy and scikit-learn. To include the reference validation and survival examples:

python -m pip install "pyplasmode[validation]"

Ten-minute example

import numpy as np
from sklearn.linear_model import LogisticRegression
import pyplasmode as ppm

rng = np.random.default_rng(1)
population = ppm.Population(
    rng.normal(size=(2_000, 100)),
    tuple(f"feature_{index}" for index in range(100)),
)

partition = ppm.partition_population(
    population,
    training_fraction=0.6,
    validation_fraction=0.2,
    seed=7,
)
samples = ppm.generate_partitioned(
    partition,
    truth=ppm.SparseTruth(features=("feature_3", "feature_17", "feature_42")),
    outcome=ppm.BinaryOutcome(probability=0.15, odds_ratio=2.0),
    sample_sizes=ppm.PartitionSampleSizes(1_200, 400, 400),
    sampling_method="without_replacement",
    seed=42,
)

train, test = samples.training, samples.evaluation
model = LogisticRegression(max_iter=1_000).fit(train.X, train.outcome.values)
ranking = tuple(train.feature_ids[index] for index in np.argsort(-np.abs(model.coef_[0])))

recovery = ppm.evaluate_ranking(ranking, train.truth, depths=(10, 20, 50))
prediction = ppm.evaluate_prediction(
    test.outcome.values,
    model.predict_proba(test.X)[:, 1],
    metric="roc_auc",
)
print(recovery.at_depth[0].recall)
print(prediction.value)

The first number is the recovery (recall in the API): the fraction of the three generating features in the model's top ten. The second is the AUC (area under the ROC curve) on held-out observations. Repeat the comparison with different seeds to estimate average performance and its Monte Carlo uncertainty. compare_paired_replicates matches two procedures' results by simulated dataset before computing paired differences, and counts failures among the matched pairs. See paired evaluation.

Source rows are split before resampling to keep training, validation and test rows disjoint. This example uses a fixed model. The validation sample is available for tuning hyperparameters.

What can be varied

  • Signal: a null, sparse, correlated, distributed or interaction structure, or a custom function.
  • Outcome: binary probability, continuous mean and spread, count rate, ordinal category probabilities or cumulative event risks at chosen times. Binary and time-to-event outcomes can take a target AUC of the generating score in place of an odds or hazard ratio (calibration).
  • Evaluation: feature and group recovery, weighted-module and graph-region coverage, reconstruction of the generating score, prediction accuracy, panel performance and ranking stability. Further functions handle tied scores and incomplete selections and compute recovery above chance. pyplasmode.metrics provides selection stability and consensus across refits, AUC under censoring, paired bootstrap differences and the gap between a fitted model's AUC and that of the generating score.

Start with Methods, then choose a signal and outcome. The evaluation guide defines each result. The validation example checks the generators and recovery metrics against known values and reference estimators. The documentation also holds the API reference.

The executable quickstart, survival example, custom signal and metrics and calibration example use synthetic inputs. The synthetic benchmark fits Cox, ridge and XGBoost across three signal structures and three target AUCs, then compares held-out AUC with recovery above chance in the top 20 features. It needs the optional model libraries: python -m pip install "pyplasmode[benchmark]".

Using it with a coding agent

The folder skills/pyplasmode is a skill package that teaches a coding agent the workflow, the choices and the common mistakes. See Coding agents.

Working with empirical data

Resampling preserves the source data's feature relationships and missingness patterns. It can reproduce individual records, so generated datasets require the same privacy protections as their source. See Data handling.

Licence

PyPlasmode uses the BSD 3-Clause License.

Metadata

Release files for pyplasmode 1.2.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 pyplasmode 1.2.1
File Size Uploaded Provenance Actions
pyplasmode-1.2.1.tar.gz 2.1 MB With provenance Details for pyplasmode-1.2.1.tar.gz

Built distribution (wheel)

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

Total release size: 2.2 MB

Release files / pyplasmode-1.2.1.tar.gz

Download URL pyplasmode-1.2.1.tar.gz
Size 2.1 MB
Tags Source
SHA-256 checksum
How to use checksums
55f6639e9bf6c36b4db41f88685dc40797a1480735af3ef2fbee2c5074b63d2b
BLAKE2b-256 checksum
How to use checksums
4959032a4a0ed0dea6e6b1d4d38d89d18568eed602f1bcf69555e807d164fc60
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 Nov 25, 2026.

Transparency log

Release files / pyplasmode-1.2.1-py3-none-any.whl

Download URL pyplasmode-1.2.1-py3-none-any.whl
Size 46.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
b4fd6eeba0a93b3ef4f58a84caa4025eb2b7c2b419ec9c79157e215c0fdca7be
BLAKE2b-256 checksum
How to use checksums
2d6baf7255c6a405105e6c337fe72e072c7c2d3bdfde05c460b9bed71afad8a0
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 Nov 25, 2026.

Transparency log

Security for pyplasmode 1.2.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.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for pyplasmode-1.2.1.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 25, 2026.

Transparency log

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