mm kinetics
github ↗starting with the reaction
my dad was reading a biochemistry paper when i noticed it, and that inspired me to start this project. i built mm kinetics in python to work with enzyme reactions and learn machine learning through a concrete problem. the project grew from implementing an equation into a pipeline that simulates reactions, fits curves, compares regression models, and estimates uncertainty.
an enzyme speeds up a reaction by binding to a substrate and converting it into a product. i started with michaelis-menten kinetics, which describes how the reaction rate changes with substrate concentration. the rate rises as more substrate becomes available, then approaches a limit as the enzyme becomes saturated. the two parameters are vmax, the limiting rate, and km, the substrate concentration at half that rate.
i also implemented a simulation that tracks free enzyme, substrate, the enzyme-substrate complex, and product over time. that gave me a second way to examine the reaction alongside the rate equation.
fitting the curve
the default run generates 100 enzymes and four substrates, producing 400 assays with ten concentration measurements each. i add noise to the simulated rates so that the fitting code works with imperfect observations. for one representative assay, i use scipy to estimate km and vmax from those measurements. the pipeline runs both an ordinary fit and a weighted fit that accounts for measurement uncertainty.
a fitted curve gives one estimate of each parameter. i added bootstrapping to examine how those estimates change when the data changes. one method resamples the measured concentration-rate pairs; another generates new noisy observations around the fitted curve. the default run repeats each method 200 times.
the resampled km estimates have a long upper tail, which makes the uncertainty visible even when the original curve looks convincing.
learning the ml workflow
learning the machine learning workflow was the hardest and most memorable part. i had to decide which information belonged in the inputs, how to compare models, and how to evaluate predictions on enzymes excluded from training.
the default target is log10(km). inputs include assay conditions such as temperature and ph, along with enzyme and substrate descriptors. i exclude identifiers, measured reaction rates, and kinetic targets from the features. for this synthetic example, i train against the known generated parameters. the single-assay curve fit above is a separate demonstration.
i split the data by enzyme, keeping all assays from each enzyme together. the default split assigns 40 enzymes to training and 20 each to validation, calibration, and testing. i compare a median baseline, linear regression, ridge regression, random forest, and gradient boosting using validation rmse. gradient boosting wins this run. i then train 40 bootstrap copies of that model on resampled training assays and use their median prediction.
reading the results
the saved run reports a test rmse of 0.078 log10 units and an r-squared of 0.977 across 80 assays from 20 held-out enzymes. those results describe performance on synthetic data whose descriptors contain the relationships used to generate the targets. they do not establish performance on experimental enzyme data.
i use the separate calibration set to construct prediction intervals. for each calibration enzyme, i take its largest absolute prediction error, then use the required ranked error to set the interval width. in the saved test set, the calibrated 95% intervals cover 96.25% of individual assay targets. they cover every assay within 95% of the test enzymes, or 19 out of 20.
the project also accepts local sabio-rk exports containing reported kinetic parameters. that path does not supply raw reaction curves, so the fitting demonstrations still use synthetic data. enzymes remain separate across the default partitions, but some studies and enzyme families are shared. the current evaluation does not measure generalization to entirely new studies or families.
the bugs along the way
unit conversion caused an early bug. i initially appended converted values one field at a time. if a later conversion failed, earlier fields already had an extra entry, breaking alignment between the output columns and their rows. i changed the code to convert each row as a unit and insert missing values for the whole normalized row on failure. regression tests check that invalid units preserve row alignment.
i also reused the validation set to calibrate intervals after selecting a model with it. that gave the same data two jobs. i introduced a separate calibration partition and added a regression test that changes its labels. the test checks that model selection and point predictions stay identical when calibration labels change.
the interval calculation needed two further fixes. i replaced a quantile calculation with the required ranked residual. i then removed a shortcut that capped the rank at the largest available error. with fewer than 19 calibration enzymes, a 95% interval requires an unbounded result. the pipeline now preserves those infinite bounds and labels them in the outputs instead of reporting a finite interval the calibration data cannot support.
through this project, i learnt how to build an ml workflow from data preparation through evaluation. comparing models was one part of it; choosing inputs, separating data, and checking uncertainty required their own work. i now have tests for the failures i encountered, alongside a configurable pipeline that saves predictions, fitted models, metrics, and figures.