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.
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.
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 1
Round 2
Round 3
Round 4
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.
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
| features | label | |||||
|---|---|---|---|---|---|---|
| kPa | PEG | PVA | NH₂ | COOH | prolif. | |
| Hydrogel 1 | 1.2 | 1 | 0 | 0 | 1 | 1 |
| Hydrogel 2 | 0.92 | 1 | 0 | 1 | 0 | 1.2 |
| Hydrogel 3 | 1.1 | 0 | 1 | 1 | 0 | 0.65 |
| Hydrogel 4 | 0.6 | 0 | 1 | 0 | 1 | 0.35 |
| Hydrogel 5 | 1.7 | 1 | 0 | 0 | 1 | 1.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
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.
Good fitdegree
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.
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.
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.
5 votes blue ·0 votes scarlet→ predicted: keeps the enzyme active
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.
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 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.
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.
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 1 · Split
Step 2 · Fit the scaler on the training set
Step 3 · Apply the same transformation to both
The mistake · Scaler fitted on everything
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. |
| R² | 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.
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.
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.
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.
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.
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:
- Load and inspect the table with pandas; drop columns that are not features; check
.info()for types and missing values. - Split 90 % training, 10 % test, with a fixed random seed.
- Scale the features with
StandardScaler, fitted on the training set only. - Train a
RandomForestRegressorwith default settings. - Cross-validate with five folds. The default model scores R² ≈ 0.64.
- Tune with
RandomizedSearchCVover 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. - Test on the held-out 10 %: R² = 0.71, mean absolute error 4.8 percentage points of retained activity.
- Predict the retained activity of a polymer that was never made, by writing its composition as a new row.
- 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
- The paper this page accompanies: A user’s guide to machine learning for polymeric biomaterials (PDF) · doi:10.1021/acspolymersau.2c00037. Its supporting information has an alphabetized glossary of every term used here.
- scikit-learn user guide — the library the tutorial uses, with a worked example for every algorithm above.
- DataCamp — the structured Python and machine learning courses our group has used to get new members started. Free alternatives include Learn Python and Codecademy.
- A user’s guide to your first self-driving liquid handling lab (PDF) — active learning and Bayesian optimization end to end, for when the model starts choosing the experiments.