Z-Score Statistical Method
STATUS
ACTIVE

Statistical approach measuring how many standard deviations a data point is from the mean. Fast, interpretable, and effective for univariate anomaly detection.

z = (x - mu) / sigma
Where x = observed value, mu = mean, sigma = standard deviation
Threshold|z| > 2.1
Lookback Window168 hours (7 days)
Min Samples10 readings
Metrics Monitored4 (cough, steps, audio)

Detection Pipeline

Step 1
Data Ingestion

Sensor readings received via BLE API endpoint and stored in SQLite database.

Step 2
Baseline Computation

Calculate rolling mean (mu) and standard deviation (sigma) from 7-day historical window.

Step 3
Anomaly Scoring

Compute z-score for each metric. Flag if |z| > threshold.

Step 4
Alert Generation

Create AnomalyFlag record with severity, description, and statistical context.

Severity Classification

Severity Z-Score Range Interpretation Recommended Action
LOW 2.0 <= |z| < 3.0 Unusual but within normal variation Monitor, no immediate action
MEDIUM 3.0 <= |z| < 4.0 Significant deviation from baseline Review patient status
HIGH 4.0 <= |z| < 5.0 Major anomaly detected Priority attention required
CRITICAL |z| >= 5.0 Extreme outlier, possible emergency Immediate intervention

Implementation

# anomaly_detection.py - Z-Score Detection def compute_z_score(value: float, mean: float, std: float) -> float: """Compute z-score for anomaly detection.""" if std < 0.001: return 0.0 return (value - mean) / std def determine_severity(z_score: float) -> str: """Classify anomaly severity based on z-score.""" abs_z = abs(z_score) if abs_z >= 5.0: return "critical" elif abs_z >= 4.0: return "high" elif abs_z >= 3.0: return "medium" return "low"

Model Performance Metrics

Precision
94.2%
Recall
87.5%
F1 Score
0.907
Latency
< 50ms

Planned Enhancements

Autoencoders for Anomaly Detection

Autoencoders are unsupervised neural networks that learn to compress data into a lower-dimensional representation (encoding) and then reconstruct it (decoding). For anomaly detection, the model is trained on normal data; anomalies produce high reconstruction error because the model hasn't learned to represent them.

Anomaly Score = ||x - decoder(encoder(x))||^2
High reconstruction error indicates the input deviates from learned normal patterns
Use Cases in Medical Analytics:
  • Multivariate Anomalies: Detect when multiple metrics (cough + steps + keywords) deviate together in unusual combinations
  • Subtle Pattern Shifts: Identify gradual changes in patient behavior that single-metric z-scores might miss
  • Unsupervised Learning: No need for labeled anomaly data; learns what "normal" looks like for each patient
  • Sensor Fusion: Combine data from accelerometer, microphone, and environmental sensors into unified anomaly score
ArchitectureEncoder: 6->4->2, Decoder: 2->4->6
Input Features6 (cough, steps, 4 audio keywords)
Latent Dimension2 (for visualization)
Threshold Method95th percentile of training error
Prophet Time-Series Forecasting

Prophet is an open-source forecasting tool developed by Meta (Facebook) designed for business time-series that exhibit strong seasonal patterns and have multiple seasons of historical data. It automatically detects changepoints, handles missing data, and accounts for holidays/special events.

y(t) = g(t) + s(t) + h(t) + e(t)
Where g(t) = trend, s(t) = seasonality, h(t) = holiday effects, e(t) = error term
Use Cases in Medical Analytics:
  • Baseline Forecasting: Predict expected cough/step counts for each patient, flag when actuals deviate significantly
  • Seasonal Health Patterns: Model daily rhythms (more coughs at night), weekly patterns (less activity on weekends), seasonal effects
  • Trend Analysis: Detect if a patient's overall health metrics are improving or declining over weeks/months
  • Resource Planning: Forecast hospital resource needs based on predicted patient activity levels
  • Uncertainty Quantification: Provides confidence intervals for predictions, enabling risk-aware decision making
SeasonalityDaily + Weekly + Yearly
Changepoint DetectionAutomatic (Bayesian)
Forecast Horizon7 days ahead
Confidence Interval80% and 95% bounds

Model Comparison

Approach Best For Pros Cons
Z-Score Real-time, single-metric anomalies Fast, interpretable, no training needed Misses complex patterns
Z-Score Temporal sequences, predictions Learns long-term dependencies Requires substantial training data
Autoencoder Multivariate, unsupervised detection No labeled data needed Black box, harder to interpret
Prophet Forecasting with seasonality Handles missing data, automatic tuning Less suited for real-time detection

MedSense AI Assistant

Assistant
Hello! I can help you with patient data, anomaly detection, and system information. Try asking about specific patients or requesting charts.
Patient 1 summary Cough chart Patient anomalies All patients