Drift Detection¶
quprep.core.drift.DriftDetector(mean_threshold=3.0, std_threshold=2.0, warn=True)
¶
Detects statistical drift between training data and new data.
Fitted during Pipeline.fit() on the post-cleaning, post-reduction
feature matrix. On transform(), compares new data against stored
training statistics and issues a QuPrepWarning if drift is detected.
Two signals are checked per feature:
- Mean shift — the difference in feature means, expressed in units
of the training standard deviation. Flagged when
|new_mean - train_mean| / train_std > mean_threshold(default 3σ). - Std ratio — the ratio of new std to training std. Flagged when
the ratio is outside
[1/std_threshold, std_threshold](default 2×, i.e. std has doubled or halved).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mean_threshold
|
float
|
Number of training standard deviations a mean shift must exceed to be flagged (default: 3.0). |
3.0
|
std_threshold
|
float
|
Maximum ratio of new std to training std before flagging (default: 2.0). A ratio of 2.0 means the new data is twice as spread out (or half). |
2.0
|
warn
|
bool
|
Whether to issue a |
True
|
Source code in quprep/core/drift.py
Functions¶
check(dataset)
¶
Check new data for drift against the training distribution.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dataset
|
Dataset
|
New data to check. Must have the same number of features as the training data. |
required |
Returns:
| Type | Description |
|---|---|
DriftReport
|
|
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If called before |
ValueError
|
If |
Source code in quprep/core/drift.py
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 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 | |
fit(dataset)
¶
Record training distribution statistics.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dataset
|
Dataset
|
Training data (post-cleaning, post-reduction). NaN values are excluded from statistics using nan-safe functions. |
required |
Returns:
| Type | Description |
|---|---|
DriftDetector
|
Returns |
Source code in quprep/core/drift.py
quprep.core.drift.DriftReport(drifted_features=list(), feature_stats=dict(), n_features_drifted=0, overall_drift=False)
dataclass
¶
Summary of drift detected between training and new data.
Attributes:
| Name | Type | Description |
|---|---|---|
drifted_features |
list of str
|
Feature names (or indices) where drift was detected. |
feature_stats |
dict
|
Per-feature drift details: |
n_features_drifted |
int
|
Number of features that exceeded the drift threshold. |
overall_drift |
bool
|
|