Robust conditional normalization of continuous markers using polynomial surface fitting over categorical and continuous covariates
Project description
covnorm
Scikit-learn compatible transformer for robust conditional Z-score normalization of a continuous marker against categorical and continuous covariates.
For each unique combination of categorical covariates, the transformer fits a polynomial surface over mu and sigma estimated per bin via Q-Q regression on Box-Cox transformed values, with iterative Tukey z-score outlier rejection. At transform time, each sample is normalized using the mu and sigma predicted from its covariate values.
Data requirement: target values must be strictly positive (Box-Cox transform). Shift your data if it contains zeros or negatives.
Supports up to 2 categorical and 2 continuous covariates.
Installation
pip install covnorm
Usage
import numpy as np
from covnorm import RobustConditionalNormalizer
# X columns: [sex, batch, age, cell_count, marker]
# sex=0, batch=1 → categorical
# age=2, cell_count=3 → continuous
# marker=4 → target to normalize
X = np.load("data.npy") # shape (n_samples, 5)
normalizer = RobustConditionalNormalizer(
categorical_cols=[0, 1],
continuous_cols=[2, 3],
target_col=4,
n_bins=6, # bins per continuous covariate
log_transform_continuous=True, # recommended when covariates span orders of magnitude
)
X_norm = normalizer.fit_transform(X)
The target column in X_norm contains Z-scores. All other columns are unchanged.
It follows the scikit-learn fit / transform / fit_transform API and is compatible with Pipeline.
Parameters
| Parameter | Default | Description |
|---|---|---|
categorical_cols |
— | Column indices treated as categorical grouping variables |
continuous_cols |
— | Column indices used as continuous covariates for surface fitting |
target_col |
— | Column index of the marker to normalize |
n_bins |
6 |
Number of bins per continuous covariate axis |
degree |
3 |
Polynomial degree of the mu/sigma surface |
n_iterations |
3 |
Iterative Tukey z-score outlier-removal passes before binning |
log_transform_continuous |
False |
Apply log10 to continuous covariates before fitting (recommended when they span orders of magnitude, e.g. age in years) |
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file covnorm-0.2.1.tar.gz.
File metadata
- Download URL: covnorm-0.2.1.tar.gz
- Upload date:
- Size: 12.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
53074c8fe6a623ddc22443ba1f114621e7efbbc6d003f50a45cbc4a5ca0c9a9b
|
|
| MD5 |
4b184cd69eb977fb45b2bce646404abb
|
|
| BLAKE2b-256 |
b7bc5812b3468f884a68ff17586cbd6a50df91d60f4a155b0c741af5bd878cd1
|
Provenance
The following attestation bundles were made for covnorm-0.2.1.tar.gz:
Publisher:
publish.yml on danilotat/covnorm
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
covnorm-0.2.1.tar.gz -
Subject digest:
53074c8fe6a623ddc22443ba1f114621e7efbbc6d003f50a45cbc4a5ca0c9a9b - Sigstore transparency entry: 1546934858
- Sigstore integration time:
-
Permalink:
danilotat/covnorm@d161c603a760995c10dff5b82f4ebbec739c4e27 -
Branch / Tag:
refs/tags/v0.2.1 - Owner: https://github.com/danilotat
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@d161c603a760995c10dff5b82f4ebbec739c4e27 -
Trigger Event:
release
-
Statement type:
File details
Details for the file covnorm-0.2.1-py3-none-any.whl.
File metadata
- Download URL: covnorm-0.2.1-py3-none-any.whl
- Upload date:
- Size: 10.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b124459db600aa4c1b79afa645bcf7b36dd6e3defdd9d4ad834777844ec1f526
|
|
| MD5 |
c3c8d99c5a7da20efd3b8fb6e7917a91
|
|
| BLAKE2b-256 |
71784932111efe727055b87c37bc3ab20a786bb146a0e6d382501ccd57859269
|
Provenance
The following attestation bundles were made for covnorm-0.2.1-py3-none-any.whl:
Publisher:
publish.yml on danilotat/covnorm
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
covnorm-0.2.1-py3-none-any.whl -
Subject digest:
b124459db600aa4c1b79afa645bcf7b36dd6e3defdd9d4ad834777844ec1f526 - Sigstore transparency entry: 1546934868
- Sigstore integration time:
-
Permalink:
danilotat/covnorm@d161c603a760995c10dff5b82f4ebbec739c4e27 -
Branch / Tag:
refs/tags/v0.2.1 - Owner: https://github.com/danilotat
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@d161c603a760995c10dff5b82f4ebbec739c4e27 -
Trigger Event:
release
-
Statement type: