SV
← Back to code
— ML Engineering

GlucoPred

Degree thesis

Forecasting blood glucose 15-60 minutes ahead for Type 1 Diabetes, trained on ~2.5 years of my child's CGM and insulin-pump data. An automated pipeline feeds a 47-column feature matrix; an LSTM beats classical baselines at every horizon, with Clarke Error Grid analysis showing where accuracy and clinical safety diverge.

Python PyTorch MLflow statsmodels Pandas NumPy DuckDB FastAPI React TypeScript Vite Tailwind CSS Recharts Vercel Data Pipeline Time-Series Forecasting
~ when Mar 2026 → Ongoing
~ status Active
~ kind School Project

GlucoPred started as my degree thesis (examensarbete), now submitted: forecasting blood glucose 15-60 minutes ahead for a person with Type 1 Diabetes, using ~2.5 years of my child's continuous glucose monitor (CGM) and insulin-pump data (Dexcom via Glooko, 5-minute intervals). All values are in mmol/L (≈18 mg/dL per mmol/L).

Pipeline

  • Automated, idempotent ZIP→DuckDB ingestion of raw CGM and pump exports (language-aware: Swedish/English)
  • CGM cleaning, sensor-session detection, and gap interpolation
  • 47-column engineered feature matrix - lags, rolling statistics, time encodings, carbs on board, and a NovoRapid pharmacokinetic insulin-on-board model (bolus + basal) - against +15 / +30 / +60 min targets, with verified zero future leakage (CI-tested)

Models & evaluation

Baselines (persistence, moving average, linear extrapolation, AR(2)) and an LSTM are scored with RMSE/MAE, time-in-range, and Clarke Error Grid zone analysis (A-E per model and horizon). The LSTM beats every baseline at all horizons, evaluated on held-out recent data.

The most interesting finding is a divergence between accuracy and clinical safety: although the LSTM is the most accurate model, some simpler baselines produce a lower fraction of dangerous-zone errors than the LSTM. The best average-error model isn't automatically the safest near hypoglycemia - surfacing that, rather than just the RMSE headline, is central to the work.

Experiment tracking

After the thesis I added MLflow for experiment tracking and a model registry, so models can be benchmarked and compared run by run. The backend serves inference from whichever version holds the registry's @champion alias.

Interface

A React + Recharts UI renders actual-vs-predicted traces with model and horizon selectors. Because the real app runs against personal medical data, it is never hosted - instead, a public demo built on entirely synthetic data is deployed separately, so the interface can be explored without exposing any real record.

Next steps

Gradient-boosting models and hyperparameter tuning, compared against the LSTM through MLflow.

CoreInfraDataMLAgentsFrontend
About this chart
Each axis is a functional pillar; the orange area shows where my effort went on this build - the further an axis reaches, the more of the work concentrated there.