Skip to content
tishad.net
SearchCtrl K

Lessons / Part 8. Machine learning on small data in plain terms

42 A first model on a problem you can solve by hand

A small network fitted to a synthetic first order batch reactor is checked against the exact solution before any real data is touched.

What people usually ask

Build a neural network to predict conversion from my reactor data. Here's the file.

What comes back

A network fitted to the real table with a reported score, and no way to tell whether the errors come from the data or from the model.

Ask this instead

Before touching my data, build the model on a problem with a known answer.
1. Generate a synthetic first order batch reactor: C = C0 exp(-k t), C0 = 1.0 mol/L, k = 0.1 per minute, 20 points from t = 0 to 40 minutes, conversion X = 1 - C/C0. No noise in the first pass.
2. Fit a small MLPRegressor (one hidden layer of 8 units) with StandardScaler in a pipeline, X against t.
3. Plot the fitted curve over the 20 points together with the analytical curve on the same axes, both labelled.
4. Print the largest absolute error in X over the 20 points and the time at which it occurs. Print the number of weights in the network beside the number of points.
5. Then add 2 percent Gaussian noise to X and repeat steps 2 to 4.
Stop there. Nothing is fitted to my real table until the noise free curve matches the exact solution to within 0.01 everywhere.

Attach: Nothing.

Why it works: With the exact answer known, every error on the plot belongs to the model or the code, and that is the only time the two can be told apart from the data.

Drafted with Fable 5.1 from my notes; chosen and edited by me.