Introduction to Machine Learning
This section is a minimal, practical introduction for biologists applying ML to tabular biology datasets (e.g. sample-by-feature tables: clinical variables, gene panels, assay readouts). It is concepts + one reproducible sklearn example — not a full ML course.
For deeper study: https://www.coursera.org/specializations/machine-learning-introduction
1. Core vocabulary
- Supervised learning: you have labels. Classification (disease vs control) or regression (predict a continuous value like age, expression level).
- Unsupervised learning: no labels. Clustering (find subtypes), dimensionality reduction (PCA/UMAP for visualisation).
- Features (X) vs target (y): rows = samples, columns = features; one column is the target you predict.
- Train / validation / test split: train fits the model, validation tunes it, test estimates real-world performance once. Never tune on the test set.
- Leakage: information from the test set (or future) leaks into training — e.g. normalising on the full dataset, selecting features using all samples. This inflates performance and fails on new data.
- Overfitting vs underfitting: overfit = memorises training noise (train high, test low); underfit = too simple (both low). More data, simpler models, and regularisation help.
- Cross-validation (CV): split train into k folds, rotate which fold validates. Use stratified k-fold for imbalanced classes.
- Class imbalance: biology is often 90/10. Accuracy lies — report precision, recall, F1, ROC-AUC, PR-AUC and the confusion matrix.
2. Minimal sklearn workflow
Prerequisites: the venv + pinned requirements.txt workflow from earlier. Add:
Verify it worked
CV F1 prints without errors; test report shows precision/recall/F1 per class — not just accuracy. If test >> CV, suspect leakage. If both are low, start simpler (fewer features, logistic regression) before trying bigger models.
3. Reproducibility checklist (biology-specific)
random_stateset everywhere; recordscikit-learn==x.y.z, Python version, and git commit hash with results.- Split by biological unit (patient/donor/batch), not by row, when rows are correlated — otherwise leakage.
- Keep batch/site info as a column; check performance per batch.
- Save the fitted pipeline (
joblib) + test IDs so anyone can reproduce the exact numbers. - On Azure: run the same script +
requirements.txt+ Dockerfile on the VM; results should match your laptop.
4. Ethics and limits
- De-identified data only outside TREs; Trusted Research Environments (SafeHaven/DataLoch) rules override everything here.
- Report limitations: sample size, selection bias, class imbalance, and that test performance ≠ clinical utility.
- Do not deploy to clinical use from this tutorial — that needs validation, governance, and monitoring far beyond this scope.