infer.monitor¶
Drift monitoring orchestrator: runs all drift checks and optionally auto-creates labeling tasks when triggers fire.
Overview¶
Ties together the pure drift statistics from core.drift with the
telemetry store and the active labeling queue.
Models¶
DriftTrigger¶
StrEnum of trigger types:
feature_psi— Feature PSI exceeded thresholdfeature_ks— Feature KS test significantreject_rate_increase— Reject rate increased beyond thresholdentropy_spike— Mean prediction entropy spikedclass_shift— Class distribution shifted
DriftAlert¶
| Field | Type | Description |
|---|---|---|
trigger |
DriftTrigger |
Which check triggered |
details |
dict |
Trigger-specific data |
severity |
"warning" \| "critical" |
Alert severity |
affected_user_ids |
list[str] |
Users affected |
affected_features |
list[str] |
Features affected |
timestamp |
datetime |
When alert was raised |
DriftReport¶
| Field | Type | Description |
|---|---|---|
alerts |
list[DriftAlert] |
All alerts raised |
feature_report |
FeatureDriftReport \| None |
Per-feature PSI/KS |
reject_rate_drift |
RejectRateDrift \| None |
Reject rate comparison |
entropy_drift |
EntropyDrift \| None |
Entropy comparison |
class_shift |
ClassShiftResult \| None |
Class distribution shift |
telemetry_snapshot |
TelemetrySnapshot \| None |
Current-window telemetry |
summary |
str |
Human-readable summary |
any_critical |
bool |
Whether any critical alert fired |
Functions¶
run_drift_check¶
Run all drift checks and return a consolidated report.
from taskclf.infer.monitor import run_drift_check
report = run_drift_check(
ref_features_df, cur_features_df,
ref_labels, cur_labels,
ref_probs=ref_probs,
cur_probs=cur_probs,
)
print(report.summary)
auto_enqueue_drift_labels¶
Create labeling tasks for drifted buckets. Selects buckets with the
lowest confidence from the current window and enqueues them via
ActiveLabelingQueue.
from taskclf.infer.monitor import auto_enqueue_drift_labels
count = auto_enqueue_drift_labels(
report, cur_features_df,
queue_path=Path("data/processed/labels_v1/queue.json"),
cur_confidences=confidences,
limit=50,
)
write_drift_report¶
Persist a drift report as JSON.
from taskclf.infer.monitor import write_drift_report
write_drift_report(report, Path("artifacts/drift_report.json"))
taskclf.infer.monitor
¶
Drift monitoring orchestrator: run checks and auto-create labeling tasks.
Ties together the pure drift statistics from :mod:taskclf.core.drift with
the telemetry store and the active labeling queue.
DriftTrigger
¶
Bases: StrEnum
Enumeration of drift trigger types.
Source code in src/taskclf/infer/monitor.py
DriftAlert
¶
Bases: BaseModel
A single drift alert raised during a check.
Source code in src/taskclf/infer/monitor.py
DriftReport
¶
Bases: BaseModel
Aggregated output of a full drift check run.
Source code in src/taskclf/infer/monitor.py
run_drift_check(ref_features_df, cur_features_df, ref_labels, cur_labels, *, ref_probs=None, cur_probs=None, cur_confidences=None, user_ids=None, psi_threshold=DEFAULT_PSI_THRESHOLD, ks_alpha=DEFAULT_KS_ALPHA, reject_increase_threshold=DEFAULT_REJECT_RATE_INCREASE_THRESHOLD, entropy_multiplier=DEFAULT_ENTROPY_SPIKE_MULTIPLIER, class_shift_threshold=DEFAULT_CLASS_SHIFT_THRESHOLD, reject_label=MIXED_UNKNOWN)
¶
Run all drift checks and return a consolidated report.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ref_features_df
|
DataFrame
|
Reference-period feature DataFrame. |
required |
cur_features_df
|
DataFrame
|
Current-period feature DataFrame. |
required |
ref_labels
|
Sequence[str]
|
Reference predicted labels. |
required |
cur_labels
|
Sequence[str]
|
Current predicted labels. |
required |
ref_probs
|
ndarray | None
|
Reference probability matrix |
None
|
cur_probs
|
ndarray | None
|
Current probability matrix |
None
|
cur_confidences
|
ndarray | None
|
|
None
|
user_ids
|
Sequence[str] | None
|
User IDs corresponding to current rows. |
None
|
psi_threshold
|
float
|
PSI threshold for feature drift. |
DEFAULT_PSI_THRESHOLD
|
ks_alpha
|
float
|
KS significance level. |
DEFAULT_KS_ALPHA
|
reject_increase_threshold
|
float
|
Reject-rate increase threshold. |
DEFAULT_REJECT_RATE_INCREASE_THRESHOLD
|
entropy_multiplier
|
float
|
Entropy spike multiplier. |
DEFAULT_ENTROPY_SPIKE_MULTIPLIER
|
class_shift_threshold
|
float
|
Class-distribution shift threshold. |
DEFAULT_CLASS_SHIFT_THRESHOLD
|
reject_label
|
str
|
Label used for rejected predictions. |
MIXED_UNKNOWN
|
Returns:
| Name | Type | Description |
|---|---|---|
A |
DriftReport
|
class: |
Source code in src/taskclf/infer/monitor.py
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 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 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 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 | |
auto_enqueue_drift_labels(drift_report, cur_features_df, queue_path, *, cur_confidences=None, limit=DEFAULT_DRIFT_AUTO_LABEL_LIMIT)
¶
Create labeling tasks for drifted buckets.
Selects buckets with the lowest confidence from the current window
and enqueues them via :class:ActiveLabelingQueue.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
drift_report
|
DriftReport
|
Output of :func: |
required |
cur_features_df
|
DataFrame
|
Current-period feature DataFrame. |
required |
queue_path
|
Path
|
Path to the labeling queue JSON file. |
required |
cur_confidences
|
ndarray | None
|
|
None
|
limit
|
int
|
Maximum number of buckets to enqueue. |
DEFAULT_DRIFT_AUTO_LABEL_LIMIT
|
Returns:
| Type | Description |
|---|---|
int
|
Number of newly enqueued items. |
Source code in src/taskclf/infer/monitor.py
write_drift_report(report, path)
¶
Persist a drift report as JSON.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
report
|
DriftReport
|
The report to write. |
required |
path
|
Path
|
Destination file path. |
required |
Returns:
| Type | Description |
|---|---|
Path
|
The path that was written. |