Code and Notebooks
Will the numbers come out the same when someone else runs it?
Three short pieces of code, each the real method with invented data: an agreement analysis for a sensor, a scorer for evaluation runs, and a summary of monitor data. Each one is written the way I write analysis for a study, with a fixed seed and the output shown.
Every script on this page is an illustrative sample. Synthetic data, not from any employer or client.
1. Agreement between a sensor and a reference
Illustrative sample
# Python. Bland-Altman agreement, the method behind the wearables page.
import numpy as np
rng = np.random.default_rng(2026) # fixed seed, reproducible
reference = rng.normal(7.0, 1.2, 40) # reference PWV, m/s
sensor = (reference + 0.25 + 0.08 * (reference - 7.0)
+ rng.normal(0, 0.45, 40)) # small bias and slope
mean_pair = (sensor + reference) / 2
diff = sensor - reference
bias = diff.mean()
sd = diff.std(ddof=1)
limits = (bias - 1.96 * sd, bias + 1.96 * sd)
slope, _ = np.polyfit(mean_pair, diff, 1) # does the gap grow?
print(f"Bias {bias:.2f}; limits {limits[0]:.2f} to {limits[1]:.2f}; slope {slope:.2f}")
# Bias 0.34; limits -0.75 to 1.42; slope 0.29A correlation would look strong here and hide the point: the gap widens at higher readings, so a single correction factor would not fix it. The plot this produces is on the wearables page.
2. Scoring repeated evaluation runs
Illustrative sample
# Python. Pass rate per test case across repeated runs, with critical failures
# counted separately. The method mirrors how SciencEye AI is scored.
import pandas as pd
runs = pd.read_csv("runs.csv") # case_id, expectation, critical, passed
by_case = runs.groupby("case_id").agg(
pass_rate=("passed", "mean"),
critical_failures=("critical", "sum"),
)
by_case["flag"] = (by_case.pass_rate < 0.95) | (by_case.critical_failures > 0)
worst = (runs[~runs.passed]
.groupby(["case_id", "expectation"]).size()
.sort_values(ascending=False).head(5))
print(by_case.sort_values("pass_rate"))
print(worst)Two different failures, two different responses: a case that fails a critical expectation blocks release; a case that fails without any critical failure usually means the expectation is written loosely, and the rubric is reviewed before the model is touched.
3. Summarising monitor data for a sitting study
Illustrative sample
# R, in a Quarto document so code, output and write-up stay together.
library(dplyr)
valid_days <- epochs |>
group_by(id, date) |>
summarise(wear_min = sum(wear), .groups = "drop") |>
filter(wear_min >= 600) # wear rule, set in advance
bouts <- epochs |>
semi_join(valid_days, by = c("id", "date")) |>
arrange(id, timestamp) |>
group_by(id, date, bout = cumsum(posture != lag(posture, default = "none"))) |>
summarise(posture = first(posture), minutes = n(), .groups = "drop")
daily <- bouts |>
filter(posture == "sitting", minutes >= 30) |>
count(id, date, name = "long_sitting_bouts") # the pre-specified outcomeThe outcome, the wear rule and the bout threshold are all decided before the data are opened. That is what stops a null result turning into a search for a different cut-off.
Where the real code lives
Client and employer analyses stay private. The code I can show runs the research assistant I built: a shared repository with more than 2,100 commits, a Python runner for the evaluations and 519 development-log entries, of which 112 were defects and 368 closed as specific changes. That work is described here.
Repository counts as of 2026-10-08.