MethylClassifier¶
Role¶
methylclassifier is the orchestration layer that applies one or more binary ECDF classifiers to new samples. The mathematical core still lives in methyl_utils/ecdf_classifier.py, but methylclassifier determines how per-chromosome models, one-vs-rest bundles, and pairwise disease heads are fused into final probabilities.
The relevant implementation files are:
packages/methylclassifier/methyl_classifier/core/classifier.pypackages/methylclassifier/methyl_classifier/core/multiclass_ovr.py
Binary Classification¶
For a single binary model, the underlying score is the ECDF log-density average described in Eq. ecdf-score and Eq. ecdf-softmax, with explicit class priors:
The code supports several ways to determine the weights $w_c$:
- fixed configuration weights,
- trimmed mean effect-size weights derived from detector output,
- fitted linear, ridge, lasso, logistic, or elastic-net models trained on validation probabilities.
The last family is best understood as a second-stage meta-model that uses per-chromosome probabilities as features. It can improve prediction, but it is no longer a single coherent generative model.
One-vs-Rest (OvR) Multiclass Fusion¶
For multiclass problems the package builds $K$ binary heads and fuses them into a $K$-class probability vector. The active implementation in multiclass_ovr.py uses binary probabilities or logits as intermediate scores and then applies a softmax-like normalization. In symbolic form,
This is a practical multiclass reduction. It is not guaranteed to recover a single joint Bayesian posterior unless the binary heads are themselves perfectly compatible. Package metadata now records ovr_inference_version and ovr_fuse_mode so multiclass semantics are explicit and reproducible.
Pairwise Control Aggregation¶
Some project layouts export only pairwise control-vs-disease detectors. In that case the package constructs the control class probability from the geometric mean of the pairwise control probabilities:
The complement $1 - \hat p_{\text{ctrl}}(x)$ is then used to form a binary control-vs-rest head before final row normalization.
This is a useful aggregation rule, but it is a heuristic. The geometric mean is not derived in the code from a global multiclass likelihood.
Bipartite Multi-Control × Multi-Disease Aggregation¶
The package also supports bipartite layouts with several control strata and several disease strata. Here it aggregates one probability column across several pairwise experts, again using geometric means. The logic is similar to Eq. geomean-control but now applied to either the control column or the disease column depending on which class head is being built.
That construction is convenient for complex cohort hierarchies, but it should be presented as a carefully engineered reduction strategy rather than a textbook probabilistic model.
Calibration¶
When enabled, the package can apply Platt scaling [platt1999] to the raw binary outputs. In effect, one learns parameters $a$ and $b$ so that a raw score $s$ is mapped to
This improves probability calibration under distribution shift or class imbalance, but it should not be confused with changing the underlying classifier likelihood.
New Modeling Features in Production¶
Recent versions of methylclassifier expose a broader post-detector modeling layer than the original binary ECDF-only story. In practice, production runs may combine several of the following:
- native multiclass histogram model export (
multiclass-classifier.pkl) from per-comparison detector outputs, - optional learned multinomial logistic head on top of histogram pre-softmax scores,
- optional isotonic calibration for probability reshaping,
- optional elastic-net stacking for chromosome-level fusion,
- optional dependence-aware block aggregation (
dependence_block_size,dependence_block_shrinkage), - hierarchical panel readout for family-level reporting.
These are all valid engineering extensions, but conceptually they sit on top of the ECDF likelihood core rather than replacing it.
Learned Multiclass Head¶
The learned head takes base multiclass score vectors $z(x)$ and fits a multinomial logistic layer:
where $n_k$ is the number of training samples in class $k$, $K$ is the number of classes, and $n_{\text{total}} = \sum_k n_k$. These weights are passed to the loss function of the multinomial logistic regression, penalizing errors on minority classes more heavily.
This is particularly important for the prostate cancer staging problem where the healthy control cohort may be two to four times larger than any individual disease stage cohort. Without balancing, the logistic head learns to predict the healthy class as the default when the pre-softmax histogram scores do not provide strong class separation (for example, when only 20% of DMP positions are covered in a test sample; see § detector coverage).
Theoretical note. Class weighting corrects for imbalance in the empirical class frequencies of the training set. It does not correct for population prevalence differences between training and deployment contexts. If the intended clinical population has very different disease prevalence from the training cohort, additional calibration against the target distribution is required.
Reproducibility. Since sklearn 1.4, the version of sklearn used to train the logistic head is saved in the model PKL metadata under the key sklearn_version. This allows detection of version mismatches between training and inference environments. The key is written by _fit_learned_multiclass_head in packages/methylclassifier/methyl_classifier/utils/multiclass_builder.py.
Missing Data Semantics¶
A practical but important detail is how the classifier handles unavailable loci. The implementation masks those loci out of the weighted average rather than imputing them with a full modeled distribution. As a result, the effective evidence for a sample depends on how many DMPs are observed for that sample.
This is a sensible engineering choice, but it means that the posterior confidence is partly a function of data availability as well as class separation.
Publication Guidance¶
The strongest defensible summary is:
- the binary head is an ECDF-based Naive Bayes style score with explicit priors and optional calibration,
- multi-chromosome fusion is a weighted ensemble,
- multiclass OvR is a reduction from binary heads to a normalized $K$-class score,
- pairwise control aggregation is heuristic,
- and fitted chromosome weights are second-stage discriminative models, not part of the original density model.
That framing is more accurate than calling the entire package a single Bayesian multiclass classifier.