On this page

This page is for the biomaterials researcher who has a spreadsheet of polymers and results, has heard that machine learning could help, and has no idea where to begin. You do not need to know how to program to read it. Every idea is introduced with a picture you can watch or play with, and the code comes last, in one place, when you are ready for it.

We move in the order a real project moves: get data, understand what a model does with it, pick a kind of model, build the pipeline that trains and checks it, and finally read what it learned. Along the way there are short self-checks. They are not graded; they are there so you can catch a misunderstanding before it costs you a month of experiments.

Why machine learning, and why now

A conventional program is a list of rules a person wrote down. Machine learning turns that around: you give the computer examples — these polymers behaved this way — and it works out rules that connect what went in to what came out. It is closer to how a new student learns a technique, by watching and trying, than to how a calculator works.

That matters for biomaterials because the design space is absurdly large. A copolymer has a composition, a chain length, an architecture, end groups, a dispersity; a hydrogel adds stiffness, crosslink density, and surface chemistry; the biology it meets adds more. No lab can test every combination, and intuition alone does not scale to five interacting variables. What we can do is make a modest, well-chosen set of materials, measure them, and let a model find the pattern that tells us where to look next.

Two things changed to make this practical. High-throughput synthesis and characterization, such as oxygen-tolerant polymerizations run in well plates, mean one person can make and test hundreds of materials in a week. And the software that fits models has become free, open source, and forgiving enough that a first model is an afternoon’s work.

The Design, Build, Test, Learn closed loopA continuous cycle of four stages — Design, Build, Test, and Learn — connected in a ring to represent closed-loop, self-driving experimentation.DesignBuildTestLearn
The Design → Build → Test → Learn loop. Machine learning lives in the Learn step: it digests the results of one round and proposes the designs for the next. Automate the other three and the loop can run itself.
Check yourselfMachine learning is most useful when…

Not quite. Then you do not need a model — use the equation. Machine learning is for the cases where the rule is unknown or too tangled to write down.

Correct. That is the sweet spot: enough variables that brute force fails, and enough measured examples for a model to learn from.

Not quite. Three points constrain almost nothing. A model fitted to them will happily tell you anything, which is worse than no model.

Step 1: Getting data

Everything downstream is limited by the data you put in. Most of the effort in a successful machine learning project goes here, not into the model.

How much data is enough?

Less than people fear. The intuition that machine learning needs millions of examples comes from image and language models. For a polymer library with a handful of well-chosen features, published studies have built useful models from around fifty materials, and a few hundred is comfortable. Past roughly a thousand observations the gains flatten, because the model has already seen the range of behaviors your features can describe.

Model accuracy against data set sizeA curve rising steeply from ten to about a hundred polymers, then bending over and flattening between one thousand and five thousand. Six milestone points along it are marked. A shaded band covers fifty to three hundred polymers.polymer ML has worked herediminishing returns10501005001,0005,00000.51number of polymers in the data set (log scale)model accuracy
The shape to expect from a tabular polymer data set. Accuracy climbs fast through the first hundred materials, because each one shows the model a new region of the design space, and flattens past a thousand, once the features' range is covered. The shaded band is where published polymer studies have built useful models. Exact numbers depend on the problem; the shape does not.

What you gain from more data depends on the model. Simple models, such as regularized linear regression or a small random forest, work well on small data sets. Neural networks generally need more. So the size of your data set is one of the first things that narrows your choice of model, which we come to in Step 3.

Let the model pick the next experiment

Suppose you have measured a dozen polymers and the model is unsure about the rest. You could make more polymers at random, or you could ask the model where it is least sure and make those. That is active learning: every round, the model reports both a prediction and an uncertainty, and the next experiment is chosen where the uncertainty is highest (explore) or where the predicted performance is best (exploit).

Round

Round 1

Active learning, round 1: 4 measured points; next experiment chosen to explore. design variable (e.g. cationic monomer fraction)responsenext: explore — most uncertaintrue response (hidden)model ± uncertainty

Round 2

Active learning, round 2: 5 measured points; next experiment chosen to explore. design variable (e.g. cationic monomer fraction)responsenext: explore — most uncertaintrue response (hidden)model ± uncertainty

Round 3

Active learning, round 3: 6 measured points; next experiment chosen to explore. design variable (e.g. cationic monomer fraction)responsenext: explore — most uncertaintrue response (hidden)model ± uncertainty

Round 4

Active learning, round 4: 7 measured points; next experiment chosen to exploit. design variable (e.g. cationic monomer fraction)responsenext: exploit — best predictedtrue response (hidden)model ± uncertainty
Four rounds of active learning over one design variable. The dashed line is the true response, which the experimenter cannot see. Blue dots are measured polymers; the blue line is the model's prediction and the shaded band its uncertainty. In rounds 1–3 the next experiment (scarlet) goes where the band is widest, and each measurement shrinks it. By round 4 the model has found the peak, and the next experiment is placed beside the best result so far to refine it — exploiting rather than exploring. Step through the rounds.

The balance between exploring and exploiting is the whole game. Explore too much and you spend your budget mapping regions you will never use; exploit too early and you converge on a local optimum while a better material sits untested. Bayesian optimization is the standard way to strike that balance, and it is the engine inside every self-driving lab, including ours.

Mined or collected?

In bioinformatics, enormous curated databases exist and most projects start by downloading one. Polymer biomaterials are not there yet. A few resources exist, such as Polymer Genome and the materials databases built for inorganic solids, but there is no central repository of polymer biological performance, and methods vary enough between labs that pooling published results is risky. Most projects in this field collect their own data, which is slower but gives you control over how every material was made and measured.

Whichever route you take, look at the data before you model it. Check for missing values, entries recorded as text that should be numbers, and measurements that are physically impossible. Two commands in the pandas library, .describe() and .info(), show the range, average, and type of every column and catch most of these problems in seconds. Keep a written record of everything you clean or remove; a model is only reproducible if the data that fed it is.

Making your own data

If you are collecting data, plan the collection like an experiment, because it is one. Design of experiments tells you which materials to make first so that every variable is varied independently and the model can attribute effects correctly. High-throughput chemistry then makes those materials at a pace a model can use: oxygen-tolerant controlled radical polymerizations such as PET-RAFT and Enz-RAFT run in ordinary well plates, and combinatorial approaches exist for hydrogels, layer-by-layer films, and gradient surfaces. Characterization has to keep up, so favor plate-compatible assays, high-content imaging, and scattering methods that batch well.

Think early about what will become a column in your table. A feature is anything you can write down for every material: monomer fractions, chain length, stiffness, charge, but also computed descriptors from the structure that cost nothing to generate. Categorical properties, such as which of three backbones a polymer uses, are converted to numbers by one-hot encoding: one column per category, holding a 1 for the category that applies and 0 otherwise.

Polymer Backbone PEG PVA PCL
A PEG 1 0 0
B PCL 0 0 1
C PVA 0 1 0

Finally, deposit the data. Your university almost certainly has a repository, and the findable, accessible, interoperable, reusable (FAIR) principles are a short checklist for making a data set that someone else, possibly you in three years, can actually use.

Check yourselfYou have careful measurements on 80 polymers. Is that enough to try machine learning?

Not quite. That is true of image and language models, not of a tabular polymer data set with a handful of features. Published polymer models have started from around 50 materials.

Correct. Eighty well-designed materials is a workable start. The size mostly narrows which models are sensible and makes honest validation essential.

Not quite. The opposite: deep networks are the models most likely to overfit 80 points. Simpler models are the right first choice.

Check yourselfIn active learning, the next experiment is chosen…

Not quite. Random sampling is a reasonable baseline, but it is what active learning is designed to beat.

Correct. Explore where uncertainty is high, exploit where the prediction is promising, and balance the two. That is the loop a self-driving lab runs.

Not quite. Cost can be folded in as a constraint, but it is not the criterion. A cheap experiment that teaches the model nothing is wasted.

Step 2: The core ideas

There is a small vocabulary that every conversation about machine learning uses, and a few ideas that separate people who get useful models from people who get fooled by them. This is that vocabulary.

Features, labels, and two kinds of learning

Each row of your table is one material. The columns you know in advance are features (the inputs; a statistician would say independent variables). The column you want to predict is the label (the output, or dependent variable). A model is a function from features to label that was chosen by looking at your examples.

When your table has labels, the task is supervised learning, which is the overwhelming majority of biomaterials work. Supervised tasks come in two flavors. If the label is a category, such as adheres / does not adhere, or pro- / anti-inflammatory, it is classification, and the model is a classifier. If the label is a number, such as percent cell viability or modulus, it is regression, and the model is a regressor. Most algorithms have a version of each.

When there are no labels, the task is unsupervised learning: find structure in the features alone, by grouping similar materials or by compressing many features into two or three that can be plotted. It is a good first look at a new data set even when you have labels.

Question Label Task
Will this copolymer keep an enzyme active after heating? yes / no Classification
What fraction of activity will remain? 0–100 % Regression
Which of these surfaces will macrophages tolerate? tolerated / not Classification
How stiff will this hydrogel formulation be? kPa Regression
Do these 200 polymers fall into natural families? none Unsupervised

What training actually does

Every model has internal numbers, its parameters, that it is free to adjust. Training is a loop: feed in the features of a material, let the model produce a prediction, compare it with the true label using a loss function (mean squared error for regression, cross-entropy for classification), and nudge the parameters in the direction that would have made the loss smaller. Repeat over the whole training set, many times, until the loss stops improving.

1 · Data

featureslabel
kPaPEGPVANH₂COOHprolif.
Hydrogel 11.210011
Hydrogel 20.9210101.2
Hydrogel 31.101100.65
Hydrogel 40.601010.35
Hydrogel 51.710011.8

2 · Model

parameters

features in, prediction out

3 · Compare

predicted
0.8
actual
1.2

how far off was it?

4 · Loss

shrinks as training goes on

One pass of training. A material's features leave the table and go through the model, which turns them into a prediction. The prediction is compared with the measured label; the gap is the loss. The loss is fed back to nudge the model's parameters, and the next material goes through. Repeated over the whole table many times, the loss falls until it stops improving.

Some numbers the model does not adjust for itself: how many trees to grow, how deep to let them get, how strongly to penalize complexity. Those are hyperparameters. You set them before training, and choosing them well is Step 4’s job.

Underfitting, overfitting, and the bias–variance tradeoff

A model that is too simple cannot capture the pattern in the data. Its predictions are poor on the materials it trained on and poor on new ones. That is underfitting, and the cure is a more flexible model.

A model that is too flexible does something more insidious: it fits the noise. Every measurement error and every quirk of your particular batch gets absorbed into the function, so the model reproduces the training data almost perfectly and then falls apart on the first new material. That is overfitting, and it is the characteristic failure of machine learning on small data sets. The reader who drags the slider below all the way to the right will see the curve thread through every point while the validation error climbs.

Model complexity, underfitting and overfittingLeft: a scatter of points along a bump-shaped curve, with a fitted curve of degree3 drawn through them and dashed ghosts for a straight line and a wildly wiggling degree-nine polynomial. Right: two curves against polynomial degree — training loss falling steadily, validation loss falling to a minimum at degree4 and then rising.feature (scaled)propertyghosts: degree 1 and degree 9123456789model complexity (degree)loss (mean squared error, log scale)training lossvalidation loss

Good fitdegree 3

Left: fourteen measured polymers (blue) and a model of adjustable complexity fitted to them — here a polynomial, whose degree is the complexity. Dashed ghosts show the simplest and most complex fits. Right: how far the model is from the training points (blue) and from a separate set of validation points it never saw (scarlet), against complexity. Training loss only ever falls. Validation loss falls, bottoms out, and rises again as the model starts fitting noise. Drag the slider.

The two failures pull in opposite directions, which is the bias–variance tradeoff. Bias is error from being too simple; variance is error from being too sensitive to the particular sample you happened to collect. Every choice you make about model complexity moves you along that curve, and the goal is the bottom of the valley in the validation loss, not the training loss.

Cross-validation: checking yourself honestly

If unseen data is the only honest test, you need some. The simplest approach is to hold a fraction of your materials out from the start and never train on them. But with eighty polymers, holding out sixteen leaves you with a small training set and a test score that swings wildly depending on which sixteen you picked.

k-fold cross-validation solves this. Split the data into k equal folds, say five. Train on four, validate on the fifth, and record the score. Then rotate: a different fold is held out each time, until every material has been used for validation exactly once. The average of the five scores is a far more stable estimate of how the model will do on new data, and the spread between them is diagnostic in its own right.

Five-fold cross-validationA bar representing the full data set, then five rows. In each row the bar is split into five blocks; one block, a different one in each row, is marked as the validation fold and the other four as training. A score appears at the right of each row, and the mean and standard deviation at the bottom.Original data setRound 1R² 0.61Round 2R² 0.68Round 3R² 0.59Round 4R² 0.66Round 5R² 0.65training foldsheld-out foldmean 0.64 ± 0.04
Five-fold cross-validation. The data set is split into five folds. In each round, one fold is held out (scarlet) and the model is trained on the other four (blue), then scored on the held-out fold. Every polymer is held out exactly once. The five scores average to R² 0.64 ± 0.04 — a far steadier estimate than one split would give, and the spread between folds is itself a diagnostic.

Read the spread like this. If every fold scores similarly and poorly, the model is biased: make it more flexible. If the average is decent but the folds disagree, the model has high variance: simplify it, regularize it, or get more data.

Check yourselfPredicting whether a hydrogel formulation will support cell growth (yes or no) from its composition is…

Not quite. Clustering has no label. Here you have one — whether growth occurred — so the task is supervised.

Correct. Labelled examples, categorical label. A classifier is the tool.

Not quite. Regression predicts a number. If the label were the number of cells, or a viability percentage, that would be regression.

Check yourselfDuring training, the training loss keeps falling but the validation loss has started to rise. The model is…

Not quite. An underfit model is poor on both sets at once. Falling training loss with rising validation loss is the signature of the opposite problem.

Correct. It is memorizing the training set, including its noise, instead of the pattern. Stop earlier, simplify, or regularize.

Not quite. Perfect convergence would bring both losses down together. Divergence between them is the warning sign.

Check yourselfIn 5-fold cross-validation, each polymer is used for validation…

Not quite. Each polymer sits in exactly one fold, and that fold is held out exactly once.

Correct. Every polymer is in the held-out fold in one round and in the training set in the other four, so the whole data set gets to be “unseen” once.

Not quite. That describes a fixed hold-out test set. Cross-validation rotates the held-out fold through the training data instead.

Step 3: The algorithm zoo

You will hear many algorithm names. You do not need to know them all; you need to recognize the family each belongs to, roughly what it assumes about your data, and when it is a sensible first try. The honest advice from the paper stands: search the literature for a similar problem, start with what worked there, and train two or three different families on the same data so you can compare.

Seeing structure: dimensionality reduction

Before predicting anything, it helps to look. Principal component analysis (PCA) finds the directions in feature space along which your materials vary most and lets you plot them in two dimensions. Nonlinear cousins, t-SNE and UMAP, do the same for data whose structure is curved or clustered. These are unsupervised: they use no labels, so a plot where materials with different outcomes land in different regions is evidence, before any model, that your features carry signal. They are also the fastest way to spot class imbalance or batch effects.

Regression with discipline

Linear regression fits a straight line, or a plane, through your data, and it is still the right first model more often than people admit: fast, transparent, and hard to overfit. Its machine learning versions add a penalty on the size of the coefficients, which is another way of limiting complexity. Ridge regression shrinks all coefficients toward zero and is useful when features are correlated; lasso can push coefficients to exactly zero, which amounts to automatic feature selection. Logistic regression is the classification analogue: a linear model whose output is squashed into a probability.

k-nearest neighbors

The simplest model that has no equation at all. To predict a new material, find the k materials in the training set closest to it in feature space and let them vote (for classification) or average (for regression). Drag the slider: with k = 1 the prediction follows whichever single neighbor happens to be nearest, noise and all; with larger k the boundary between classes smooths out.

k-nearest neighbors classificationTwo overlapping clouds of points, blue and scarlet, and a grey query point between them. The five nearest labelled points are ringed and joined to the query by dashed lines.feature 1 (e.g. cationic fraction)feature 2 (e.g. chain length)new polymer

5 votes blue ·0 votes scarlet→ predicted: keeps the enzyme active

5
k-nearest neighbors. Sixty polymers, each already tested and labelled — blue kept an enzyme active, scarlet did not — plotted by two features. The grey point is a new polymer. To classify it, find the k labelled polymers nearest to it and let them vote. Drag the slider to change k, and click anywhere in the plot to move the new polymer.

Nearest neighbors is a good sanity check, and it is a warning about scaling: “closest” is measured with the raw feature values, so a feature that ranges 0–1000 will drown one that ranges 0–1 unless you scale them first. That comes back in Step 4.

Support vector machines

A support vector machine (SVM) draws the boundary between two classes that leaves the widest possible margin on either side. Only the points closest to the boundary, the support vectors, determine where it goes; the rest could move and nothing would change, which makes the model robust.

Support vector machine margin and a non-linear caseTwo clusters of points separated by a straight line with dashed margin lines on either side; three points sit on the margins and are circled. A second panel shows one class forming a ring around the other, with a dashed circular boundary between them.marginfeature 1feature 2LinearNeeds a kernelfeature 1
Left: a support vector machine places the boundary (solid) where the margin (dashed) is widest. Only the ringed points — the support vectors — touch the margin and decide where it goes. Right: two classes no straight line can separate. A kernel maps the points into a space where a flat boundary works, which projects back here as a curve.

When no straight boundary works, SVMs use a kernel: a transformation that lifts the data into a higher-dimensional space where a flat boundary does separate the classes. Try a linear kernel first, then a radial basis function kernel, and if the second is not clearly better the problem is probably linear. SVMs do well on small data sets with many features and less well on large, noisy, overlapping ones.

Decision trees

A decision tree asks a sequence of yes/no questions about the features, one per node, and arrives at a prediction at a leaf. Training chooses the questions that split the data most cleanly. Trees are easy to read, handle features on different scales without complaint, and capture nonlinear and interacting effects.

A decision tree classifying a hydrogelA tree with a root question, stiffness greater than 5 kilopascals; two child questions, PEG fraction greater than 20 percent and net charge cationic; and four leaves, low, moderate, moderate and high growth. The route yes, yes to the high growth leaf is highlighted and a dot travels along it.NEW HYDROGEL7 kPa · cationic · 15 % PEGnoyesnoyesnoyesstiffness > 5 kPa?PEG fraction > 20 %?net charge cationic?low growthmoderate growthmoderate growthhigh growthpredicted: high growth
A decision tree for cell growth on a hydrogel. Each internal node asks one yes/no question about a feature; each leaf is a prediction. A new hydrogel — 7 kPa, cationic — enters at the top and follows the answers down to a leaf. Training chose the questions and the thresholds; they are what the tree learned.

A single tree is also fragile: it will happily grow until every leaf holds one training point, which is overfitting in its purest form, and a small change in the data can produce a completely different tree. That is why in practice trees are almost always used in groups, which is Step 4’s ensembles section.

Neural networks

An artificial neural network passes the features through layers of simple units. Each unit takes a weighted sum of the layer before it, applies a nonlinear squashing function, and hands the result on. Stacked enough times, that is flexible enough to represent almost any function. Training adjusts the weights by backpropagation: the loss at the output is traced backward through the layers to assign blame to every weight, and each is nudged accordingly.

A fully connected neural networkFour columns of circles — five inputs labelled stiffness, PEG, PVA, NH2 and COOH, six hidden units, four hidden units, and one output labelled proliferation — with every unit connected to every unit in the next column. Pulses travel along the connections from left to right, one layer at a time.stiffnessPEGPVANH₂COOHproliferationinputhidden layersoutputforward: features → prediction · backward: loss → weight updates
A forward pass through a small neural network. Each circle is a unit: it takes a weighted sum of everything in the layer before it, applies a squashing function, and passes the result on. The weights on the connections are the parameters, and there are already a few hundred of them here. Training runs the pass forward, measures the loss at the output, and sends the blame backward through the same connections to adjust the weights.

That flexibility is the strength and the hazard. Networks with several hidden layers (deep learning) have transformed image, text, and sequence problems, where the raw input has structure that the network can learn to see. Specialized architectures follow the data: convolutional networks for images, graph networks for molecules drawn as atoms and bonds, recurrent networks for sequences. On a table of a hundred polymers with eight features, a neural network usually overfits, and a random forest usually wins.

Others you’ll hear about

Gaussian processes are regression models that return an uncertainty with every prediction as a matter of course, which makes them the natural partner for active learning and Bayesian optimization. They are computationally heavy above a few thousand points, which is not a problem in this field. Autoencoders are neural networks trained to compress and then reconstruct their input; the compressed representation can be a learned, low-dimensional description of your materials. Ensembles, which combine many models into one, are covered in Step 4 because they are as much a training strategy as an algorithm.

Check yourselfYou increase k in a nearest-neighbors classifier from 1 to 15. The boundary between classes becomes…

Correct. More neighbors vote, so a single noisy point can no longer flip the prediction on its own. Too large a k, though, and the model starts ignoring real local structure.

Not quite. The jagged boundary belongs to small k, where each prediction tracks whichever single neighbor is nearest.

Not quite. k is the model’s main knob. It changes what the model predicts, not just how fast.

Check yourselfA model that reports an uncertainty alongside every prediction is especially valuable for…

Not quite. Error bars are nice, but that is not why uncertainty matters here.

Correct. Uncertainty tells you where the model does not know, which is exactly where the next measurement teaches it the most.

Not quite. Encoding is a data-preparation step and has nothing to do with the model’s confidence.

Step 4: Building the pipeline

A model is one line of code. The pipeline around it, how the data is represented, split, scaled, scored, and tuned, is where projects succeed or quietly go wrong.

Representing polymers as numbers

The model only sees the table, so how you turn a material into a row is the most consequential decision in the project. For copolymers, the monomer fractions and chain length are a natural start. Computed descriptors of the monomers, such as hydrophobicity, charge, or molecular volume, let the model generalize to monomers it has not seen. Chemists use text notations, SMILES and its polymer extension BigSMILES, to encode structure in a machine-readable way, and composition-based feature vectors summarize a formulation as a fixed-length list. Whatever you choose, the representation should let past, present, and future materials be written the same way, so the model keeps working as the library grows.

Two further preprocessing steps are common. Augmentation creates additional training examples by transforming existing ones; it is standard for images and increasingly available for chemical structures. Class imbalance, where one outcome is rare, can push a classifier into always predicting the common class; resampling the rare class, or synthetic oversampling, corrects for it.

Splitting and scaling without leaking

Before anything else, set aside a test set and do not look at it again until the very end. The paper’s tutorial holds out 10 %; 20 % is common. The split should be random, and for classification it should be stratified, so each class is represented proportionally in both halves. Fix the random seed so the split, and every later randomized step, can be reproduced.

Next, scale the features. Most algorithms measure distances or fit coefficients that are sensitive to the units of each column, so a chain length in the hundreds will dominate a fraction between 0 and 1. Standard scaling subtracts each feature’s mean and divides by its standard deviation. The trap is where those numbers come from: compute them on the training set only, then apply the same transformation to the test set. If the test set’s values inform the scaling, information has leaked from the data you promised not to look at.

Step

Step 1 · Split

Twenty points on a stiffness axis; two are marked as the held-out test set.024681012stiffness (kPa)TEST SET · 2 of 20put away until the very end18 training points (blue) · 2 test points (scarlet)

Step 2 · Fit the scaler on the training set

A ruler marking the mean and one standard deviation, computed from the eighteen training points only; the two test points are greyed out.024681012stiffness (kPa)mean 3.6−1 sd+1 sdStandardScaler fitted on the 18 training points only — the grey test points play no part

Step 3 · Apply the same transformation to both

All twenty points shown on a scaled axis, where the training mean is zero and one standard deviation is one; the test points are transformed with the same numbers.-2-1012scaled stiffness (value − mean) ÷ sdtraining mean → 0every point, test included, uses the training mean (3.6) and sd (2.5)this is what the model sees

The mistake · Scaler fitted on everything

The ruler fitted to all twenty points, including the test set; its mean and spread differ from the training-only ruler.024681012stiffness (kPa)mean 4.1−1 sd+1 sdfitted on all 20: mean 3.6 → 4.1, sd 2.5 → 2.8 — the test set has leaked into training
Twenty hydrogels and one feature, stiffness. Step 1 sets two aside as the test set. Step 2 fits the scaler — a mean and a standard deviation — on the eighteen training points only. Step 3 applies that same mean and spread to every point, test included, giving the scaled values the model actually sees. The last panel is the mistake: fitting the scaler on all twenty lets the test points shift the mean and spread, so the model has been shown something about data it was never supposed to see.

Measuring success

You need a number that says how good the model is, and the right number depends on the task.

Metric Task What it tells you
Mean squared error (MSE) Regression Average squared miss. Penalizes big misses heavily; in squared units.
Mean absolute error (MAE) Regression Average miss, in the label’s own units. Easy to explain to a chemist.
Regression Fraction of the label’s variation the model explains; 1 is perfect, 0 is no better than the mean.
Accuracy Classification Fraction of correct calls. Misleading when one class is rare.
Precision, recall, F1 Classification How many flagged materials were real hits, how many real hits were flagged, and their balance.
ROC curve, AUC Classification How well the model ranks positives above negatives across every threshold.

Two rounds of evaluation are needed. During development, cross-validation scores guide your choices of model and hyperparameters. Once everything is fixed, the held-out test set gives the final, reportable number, and it is the only number that has never influenced a decision. Report both, and say which is which.

Tuning hyperparameters

Hyperparameters are set before training, so choosing them is a search problem. Grid search tries every combination of a few values per hyperparameter, which is thorough and expensive; with four hyperparameters at five values each, that is 625 models. Random search samples combinations at random from the same ranges and, for the same budget, usually does better, because it does not waste trials varying hyperparameters that turn out not to matter. Bayesian optimization goes further, treating the search itself as an active learning problem and choosing each trial based on the results so far.

Tune with cross-validation on the training set, never on the test set, and expect modest gains. Tuning polishes a sensible model; it does not rescue a poor representation or leaked data.

Ensembles: many weak models, one strong one

An ensemble trains many models and combines their predictions, by averaging for regression or voting for classification. The individual models are allowed to be mediocre; what matters is that their errors are different, so they cancel.

Five decision trees averaged into a random forest predictionFive small trees side by side, each with a highlighted path from root to one leaf carrying a number: 68, 74, 65, 77 and 71. Arrows lead from the leaves to a box reading average 71 percent.cationic > 30 %?DP > 90?anionic > 5 %?68tree 1DP > 120?cation. > 20 %?PEG > 10 %?74tree 2anionic > 5 %?cation. > 40 %?butyl > 15 %?65tree 3cationic > 25 %?methyl > 10 %?DP > 60?77tree 4PEG > 20 %?DP > 100?cation. > 35 %?71tree 5average = 71 % retained activity
Five trees from a random forest, all predicting the same polymer. Each tree was trained on a different random resample of the data and was only allowed to consider a random subset of features at each split, so they ask different questions and disagree a little. The scarlet path is the route this polymer takes through each tree; the forest's prediction is the average of the five leaves. Real forests use hundreds of trees.

A random forest builds hundreds of decision trees, each on a random resample of the training data (bagging) and each restricted to a random subset of features at every split. No single tree overfits in a way the others share, and the average is stable, accurate, and nearly as easy to interpret as one tree. It is the model the paper’s tutorial uses, and a strong default for tabular biomaterials data. Boosting takes a different route: it trains trees in sequence, each one focused on the errors of the last. Gradient-boosted trees, of which XGBoost is the best known, often edge out random forests on accuracy at the cost of more hyperparameters to tune. Ensembles of different algorithms, combined by voting, are a final option when no single family is clearly best.

Check yourselfYou fit the scaler on the whole data set, then split into training and test sets. What went wrong?

Not quite. The formula is fixed, but its parameters — the mean and standard deviation — were computed using the test set. That is leakage.

Correct. Fit the scaler on the training set only, then apply the same transformation to the test set. The test set must never influence anything the model sees.

Not quite. Tree models are indeed insensitive to scaling, but that is a separate point. The pipeline mistake is the order, and it would bite any model that does depend on scale.

Step 5: Interpreting the model

A trained, tuned, and tested model is a tool. Two things it can do for you: predict how materials you have not yet made will behave, and tell you which features drove the prediction.

Predicting new materials

Prediction is the point. Write down the features of candidate materials, pass them through the same scaler and model, and rank the results. Then make the top few and measure them: the comparison between predicted and measured is both the test of the model and the next round of training data. A parity plot of predicted against actual values is the standard picture. A perfect model would put every point on the diagonal; the scatter around it is the error you should expect on the next polymer, and any systematic curve away from the line, such as overpredicting weak materials and underpredicting strong ones, tells you where the model is missing something.

Predicted versus actual retained enzyme activityA scatter of about sixty points around a diagonal line from the origin to 70 on both axes. The scatter is tight at low values and widens at high values, where points sit below the diagonal. The annotation reads R squared 0.71, MAE 4.8.001010202030304040505060607070perfect modelR² = 0.71MAE = 4.8Actual retained activity (%)Predicted (%)
A parity plot: each point is one test-set polymer, placed by its measured retained activity (horizontal) and the model's prediction (vertical). The diagonal is a perfect model. Points below it were underpredicted, points above overpredicted, and the width of the band is the error to expect on the next polymer. Illustrative data with the tutorial's headline numbers.

Which features matter?

Some models explain themselves. The coefficients of a linear model are effect sizes; a random forest reports how much each feature reduced impurity across all its splits. Model-agnostic methods work for everything else. LIME fits a small, interpretable model around a single prediction to explain that one case. SHAP (Shapley additive explanations) is the current standard: for every prediction it assigns each feature a contribution, positive or negative, so that the contributions sum to the difference between that prediction and the average. Summed over the data set, SHAP values give a global importance; plotted per material, they show direction, whether high values of a feature push the prediction up or down.

SHAP summary plot of a random forest predicting retained enzyme activitySeven rows of dots. In the top two rows, cationic monomers, scarlet high-value dots lie to the right of zero and blue low-value dots to the left. In the third row, sulfopropyl methacrylate, the pattern is reversed. The remaining rows cluster near zero.-10-50+5+10+15SHAP value — impact on predicted retained activity (percentage points)Diethylaminoethyl MA (cationic)Dimethylaminopropyl MA (cationic)Sulfopropyl MA (anionic)Degree of polymerizationMethyl MAButyl MAPEG methyl ether MAHighLowFeature value
A SHAP summary plot. Each row is a feature, each dot one polymer. A dot's horizontal position is how much that feature pushed that polymer's predicted retained activity up or down; its color is the feature's value, low (blue) to high (scarlet). The two cationic monomers sit high and to the right: more of them, higher predicted activity. The sulfonated monomer runs the other way. Chain length barely moves the prediction.

That is where machine learning stops being a black box and starts being a hypothesis generator. If the model says cationic monomer content raises enzyme stability and a sulfonated monomer lowers it, that is a statement about mechanism you can go and test.

Check yourselfIn a SHAP summary plot, a feature whose high values (red points) sit to the right of zero…

Correct. Position is the contribution to the prediction, color is the feature value. High values on the right means more of that feature pushed the prediction up.

Not quite. An unimportant feature sits in a tight cluster at zero, regardless of color.

Not quite. The plot does not encode feature type. Position encodes effect on the prediction, color encodes the feature’s value.

Go hands-on

The paper comes with a Google Colab notebook that runs the whole pipeline on a real data set from our lab, in a browser, with nothing to install. Here is what it does, so you know what you are looking at when you open it.

The problem: glucose oxidase is an enzyme that loses activity when heated. Wrapping it in the right synthetic copolymer can protect it. The data set has 624 polymer–enzyme complexes; the features are the composition of each copolymer (fractions of nine monomers) and its degree of polymerization, and the label is the enzyme’s retained activity after a denaturing stress, in percent.

The pipeline, step by step:

  1. Load and inspect the table with pandas; drop columns that are not features; check .info() for types and missing values.
  2. Split 90 % training, 10 % test, with a fixed random seed.
  3. Scale the features with StandardScaler, fitted on the training set only.
  4. Train a RandomForestRegressor with default settings.
  5. Cross-validate with five folds. The default model scores R² ≈ 0.64.
  6. Tune with RandomizedSearchCV over the number of trees, tree depth, features per split, and minimum samples per split — 100 random combinations, each cross-validated. The best model’s cross-validated MSE improves from about 56 to about 55.
  7. Test on the held-out 10 %: R² = 0.71, mean absolute error 4.8 percentage points of retained activity.
  8. Predict the retained activity of a polymer that was never made, by writing its composition as a new row.
  9. Explain with SHAP: cationic monomers raise retained activity; the sulfonated monomer lowers it; chain length matters less than composition.

The core of it, in the only code on this page:

from sklearn.model_selection import train_test_split, cross_val_score
from sklearn.preprocessing import StandardScaler
from sklearn.ensemble import RandomForestRegressor

X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.10, random_state=42)
scaler = StandardScaler().fit(X_train)          # fit on the training set only
model = RandomForestRegressor(random_state=42)
model.fit(scaler.transform(X_train), y_train)
print(cross_val_score(model, scaler.transform(X_train), y_train, cv=5, scoring="r2").mean())

An R² of 0.71 is a good, not perfect, model, and the paper is candid about why: published polymer models range from about 0.5 to 0.98 depending on how well the features describe what governs the property, how much data there is, and the choices above. Improving it is the research.

Open the tutorial notebook in Colab

Further reading