ddmc.logistic_regression¶
Helpers for using DDMC cluster centers as features in a logistic regression classifier, to predict clinical/genetic features of CPTAC patients (e.g. mutation status, tumor vs. NAT, hot/cold immune infiltration).
ddmc.logistic_regression ¶
Logistic Regression Model functions to predict clinical features of CPTAC patients given their clustered phosphoproteomes.
Contains
normalize_cluster_centers: mean-centersDDMCcluster centers along the patient dimension, for use as classifier features.get_highest_weighted_clusters: picks out the clusters a fitted classifier weighted most heavily.plot_cluster_regression_coefficients/plot_roc: plotting helpers for a classifier's per-cluster coefficients and its cross-validated ROC curve.
normalize_cluster_centers ¶
normalize_cluster_centers(centers: ndarray) -> np.ndarray
Mean-center cluster centers along the patient/sample dimension.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
centers
|
ndarray
|
Cluster centers of shape (n_samples, n_components), e.g.
from |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
|
ndarray
|
zero mean across samples, same shape as |
Source code in ddmc/logistic_regression.py
29 30 31 32 33 34 35 36 37 38 39 40 41 | |
get_highest_weighted_clusters ¶
get_highest_weighted_clusters(
model: DDMC, coefficients: ndarray, n_clusters: int = 3
) -> list[int]
Pick out the (nonempty) clusters a fitted classifier weighted most heavily.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
DDMC
|
The fitted |
required |
coefficients
|
ndarray
|
Per-cluster classifier coefficients, e.g.
|
required |
n_clusters
|
int
|
Maximum number of top clusters to return. |
3
|
Returns:
| Type | Description |
|---|---|
list[int]
|
Up to |
list[int]
|
absolute coefficient magnitude. |
Source code in ddmc/logistic_regression.py
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 | |
plot_cluster_regression_coefficients ¶
plot_cluster_regression_coefficients(
ax: Axes,
lr: Any,
hue: Sequence[str] | None = None,
title=False,
) -> None
Plot LR coeficients of clusters.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ax
|
Axes
|
Axes to plot onto. |
required |
lr
|
Any
|
A fitted scikit-learn linear classifier exposing |
required |
hue
|
Sequence[str] | None
|
If given, per-cluster-run labels formatted as
|
None
|
title
|
str | bool
|
If given (and not |
False
|
Source code in ddmc/logistic_regression.py
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 | |
plot_roc ¶
plot_roc(
classifier: Any,
X: ndarray,
y: ndarray | Series,
cv_folds: int = 4,
title=False,
return_mAUC: bool = False,
kfold: str = "Stratified",
ax: Axes | None = None,
) -> float | None
Plot Receiver Operating Characteristc with cross-validation folds of a given classifier model.
Fits a fresh copy of classifier on each cross-validation fold, plots
the mean ROC curve (+/- 1 SEM band) across folds, and optionally
returns just the mean AUC instead of plotting.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
classifier
|
Any
|
A scikit-learn-compatible classifier exposing |
required |
X
|
ndarray
|
Feature matrix of shape (n_samples, n_features). |
required |
y
|
ndarray | Series
|
Binary target labels of shape (n_samples,). |
required |
cv_folds
|
int
|
Number of cross-validation folds. |
4
|
title
|
str | bool
|
If given (and not |
False
|
return_mAUC
|
bool
|
If True, skip plotting and just return the mean AUC. |
False
|
kfold
|
str
|
Cross-validation strategy: |
'Stratified'
|
ax
|
Axes | None
|
Axes to plot onto; defaults to the current axes ( |
None
|
Returns:
| Type | Description |
|---|---|
float | None
|
The mean AUC across folds if |
float | None
|
(the ROC curve is plotted onto |
Source code in ddmc/logistic_regression.py
106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 | |