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.0.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.0-py3-none-any.whl (7.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: covnorm-0.1.0.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.0.tar.gz
Algorithm Hash digest
SHA256 24583ca00d5403eb7065e17a2a24b544fb1563e4b6f43d31a28f2cf5b8d13d9d
MD5 b6c85d13469eb5ebcdffb5cfefb0d564
BLAKE2b-256 1f86ac21078870bd3a84f5860f0497c7c965ccb89c8fde994e5472962a569383

See more details on using hashes here.

File details

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

File metadata

  • Download URL: covnorm-0.1.0-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.0-py3-none-any.whl
Algorithm Hash digest
SHA256 5cbb7e8848715b235a18fcc2ded72007b8586ca5172089133c71ddf0628356d4
MD5 f5b21f3e550ec3400651565f059887a0
BLAKE2b-256 d5598a1ad2c72f60ee4f03ed83a476499ec3eda6eaaf2cbf034515157f761aed

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