Overview
The monitoring module creates comprehensive summaries of model prediction streams, tracking alert rates, risk distributions, performance metrics, and potential data drift. It’s designed for real-time monitoring of production ML systems.Function Signature
deployment/monitoring.py:7
Usage Example
Output Structure
The function returns a dictionary with the following keys:timestamp_utc
Type:str
ISO 8601 formatted UTC timestamp indicating when the summary was generated.
samples_observed
Type:int
Total number of samples in the prediction batch.
alert_count
Type:int
Number of samples that triggered alerts (where alert_flags == True).
alert_rate
Type:float
Proportion of samples triggering alerts: alert_count / samples_observed.
Useful for:
- Detecting unusual spikes in high-risk predictions
- Triggering operational alerts when rate exceeds thresholds
- Capacity planning for clinical review workflows
mean_risk_probability
Type:float
Average predicted risk probability across all samples.
risk_probability_std
Type:float
Standard deviation of risk probabilities (population std, ddof=0).
High variance indicates diverse risk profiles in the batch.
estimated_data_drift
Type:float
Simple drift indicator computed as abs(mean_risk_probability - 0.5).
- Near 0.0: Predictions centered around 50% (balanced)
- Near 0.5: Predictions skewed toward 0% or 100% (potential drift)
stream_latency_ms_per_row
Type:float
Average inference latency per sample in milliseconds.
first_alert_index
Type:int | None
Index of the first sample that triggered an alert. None if no alerts occurred.
Useful for:
- Identifying when in a batch alerts began
- Time-series analysis of alert patterns
- Quick access to first high-risk case
Example Output
Implementation Details
Source code fromdeployment/monitoring.py:7-26:
Integration with CPU Inference
Combine with CPU inference metrics:Logging and Persistence
Store monitoring summaries for time-series analysis:Alert Thresholds
Define alert logic based on your clinical workflow:Drift Detection
Theestimated_data_drift metric is a simple heuristic. For production: