Skip to main content

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 with Tukey's fence outlier rejection. At transform time, each sample is normalized using the mu and sigma predicted from its covariate values.

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
    degree=2,   # polynomial degree for surface fitting
)

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 2 Polynomial degree of the mu/sigma surface

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

covnorm-0.1.1.tar.gz (9.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

covnorm-0.1.1-py3-none-any.whl (7.7 kB view details)

Uploaded Python 3

File details

Details for the file covnorm-0.1.1.tar.gz.

File metadata

  • Download URL: covnorm-0.1.1.tar.gz
  • Upload date:
  • Size: 9.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.12

File hashes

Hashes for covnorm-0.1.1.tar.gz
Algorithm Hash digest
SHA256 0052f1cc8fca6457c89269bd188d8921f4d94ca1962bb01cabcf57bdceec5774
MD5 328d3e8a943317f5633c3f38339232d9
BLAKE2b-256 730fb42c034a110b3258f6407fb04b3c9c07a236705a1fc78dcbd9cc10237711

See more details on using hashes here.

File details

Details for the file covnorm-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: covnorm-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 7.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.12

File hashes

Hashes for covnorm-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 3f07437c4202342486b1c09c7159f4fb0d70539ac53e0f9326ad0fa2e3d75cec
MD5 e71b747f3c8601cd01778fbab6d4b854
BLAKE2b-256 4be9abe95e96a5f2521272d999b9f7bcca877fec3fa0ee312fbde4762e6e16b0

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page