Author's Website: www.CameronSummers.com
- Open-source technical source of truth: InsuLearner on GitHub
- Hosted product for people who do not want to run code locally: Insulearner Web
- Public updates and release/blog context: CameronSummers.com
This code can have significant impact on insulin dosing. There are no guardrails included here so it's possible to get poor results in some circumstances. Check with your doctor before making any changes to dosing settings.
This is the code underlying my article, where I describe the machine-learning approach used to estimate pump settings.
InsuLearner estimates:
- Carbohydrate Ratio (CIR)
- Basal Rate
- Insulin Sensitivity Factor (ISF)
Supported data sources:
The model fits linear regression over aggregated carb/insulin windows and derives CIR + basal,
then uses CSF (K) and CIR to estimate ISF.
- Python
>=3.9,<4.0
pip install insulearnerOr for development:
git clone https://github.com/scaubrey/InsuLearner
cd InsuLearner
pip install -e .The package installs a CLI entrypoint: insulearner.
insulearner <your_tidepool_email> <your_tidepool_password> \
--num_days 60 \
--height_inches 72 \
--weight_lbs 200 \
--gender maleIf you already know CSF:
insulearner <your_tidepool_email> <your_tidepool_password> --num_days 60 --CSF 4.2insulearner --source nightscout \
--nightscout_url https://your-site.example.com \
--nightscout_token <token-if-used> \
--nightscout_api_secret <api-secret-if-used> \
--num_days 30 \
--CSF 12.5Notes:
--sourcedefaults totidepool.- For
--source tidepool, positionaltp_username tp_passwordare required. - For
--source nightscout,--nightscout_urlis required.
Nightscout compatibility note:
- InsuLearner supports the main Nightscout data needed for analysis:
entries,treatments, andprofile. - Nightscout deployments vary in how they store and filter
entriesdata. InsuLearner now handles common variants usingdate,mills, andcreated_at, with a client-side fallback when server-side filtering returns no rows. - Basal reconstruction remains the most deployment-specific part of Nightscout support, so results can still vary across custom setups, plugins, and treatment event conventions.
- If you run into a compatibility issue, please open a GitHub issue and include a redacted sample of the relevant Nightscout JSON shape.
--num_days: number of days to analyze--agg_period_window_size_hours: aggregation window size in hours (default:24)--agg_period_hop_size_hours: hop size in hours (default:24)--estimate_agg_boundaries: estimate aggregation boundaries via autocorrelation-like logic
from InsuLearner import (
TidepoolUser,
NightscoutUser,
TidepoolAPI,
NightscoutAPI,
analyze_settings_lr,
)Use .env.test in the repo root so you do not re-enter credentials each run.
- Copy template:
cp .env.test.example .env.test-
Fill values in
.env.test. -
Run tests from PyCharm or terminal.
tests/conftest.pyauto-loads.env.test.
Important:
.env.testis git-ignored..env.test.exampleis safe to commit.
Run all non-live tests:
pytest -q -m "not live"Run all tests including live (requires credentials):
pytest -qRun only live parity tests:
pytest -q -m "live"Run lint:
ruff check .- PR/Push CI runs non-live tests only.
- Live API parity tests are split into a manual GitHub Actions workflow.
See RELEASE.md for the checklist.
Special thanks to Tidepool for serving the diabetes community.
