Chapter 2 of Foundations
Machine learning fundamentals
What a model is, how to fit one, and above all how to find out honestly whether it works. You will build regression and classification models with scikit-learn on real chemistry and medical data, and learn the evaluation habits that separate a useful model from a misleading one.
What you will be able to do
- Explain supervised learning as fitting a function \(f(x;\theta)\) by minimising a loss, and say where it helps and where it fails in chemistry and biology.
- Fit linear regression from scratch with the normal equation and gradient descent, then with scikit-learn’s estimator API.
- Evaluate a model honestly against a baseline with a held-out test set, MAE, RMSE, \(R^2\), parity plots and residual analysis.
- Diagnose overfitting with learning and validation curves, and control it with ridge, lasso and cross-validated hyperparameter search.
- Build and judge classifiers with confusion matrices, precision, recall, F1, ROC and precision–recall curves, including imbalanced classes.
- Assemble leak-free pipelines with scaling, imputation and encoding, and recognise the leakage patterns that plague scientific datasets.
Schedule
| Episode | Cumulative time | Questions |
|---|---|---|
|
2.1What is machine learning? 25 min teaching + 10 min exercises |
35 min |
|
|
2.2Linear regression from scratch, then scikit-learn 40 min teaching + 20 min exercises |
1 h 35 min |
|
|
2.3Evaluating models honestly 35 min teaching + 20 min exercises |
2 h 30 min |
|
|
2.4Overfitting, regularisation and cross-validation 45 min teaching + 25 min exercises |
3 h 40 min |
|
|
2.5Classification 40 min teaching + 25 min exercises |
4 h 45 min |
|
|
2.6Pipelines, preprocessing and data leakage 40 min teaching + 25 min exercises |
5 h 50 min |
|
|
Lab 2First end-to-end ML project: predicting solubility 90 min |
7 h 20 min | Predict the aqueous solubility of 1,128 small molecules from five descriptors, from a reproducible split and a baseline through cross-validated ridge and kNN pipelines to a parity plot, an error analysis of the worst-predicted molecules and a written conclusion. Optional extension: turn it into a soluble/insoluble classifier with a confusion matrix and ROC curve. |
| QuizChapter 2 checkpoint | 7 h 20 min | Ten questions covering the whole chapter. |
Lab
Lab 2, 90 min
First end-to-end ML project: predicting solubility
Predict the aqueous solubility of 1,128 small molecules from five descriptors, from a reproducible split and a baseline through cross-validated ridge and kNN pipelines to a parity plot, an error analysis of the worst-predicted molecules and a written conclusion. Optional extension: turn it into a soluble/insoluble classifier with a confusion matrix and ROC curve.
Dataset: ESOL / Delaney aqueous solubility (downloaded at runtime with checksum; see data/README.md)
Before you start
If you want the derivations behind the methods, the maths refresher covers vectors, dot products, gradients and the normal distribution. Each episode also has collapsible deep dive boxes with the mathematics; they are optional.