Skip to content
Tutorials Center
My learning

Topics

Lesson 39 of 49 ยท Machine Learning in Biology

Chapter 8 Overview: Machine Learning in Biology

A map of machine learning for biological data: classification, regression and clustering tasks, the standard workflow, and the pitfalls that make biology special.

Biology produces more data than any person can read. A single sequencing run yields hundreds of millions of reads; a proteomics experiment measures thousands of proteins; a public database lists millions of genetic variants. Machine learning is the set of methods that let a computer find patterns in such data and make predictions on new examples: is this DNA segment a promoter, is this variant likely to damage the protein, which patients' tumors resemble each other?

This chapter is not a general machine-learning course. The site's Machine Learning and scikit-learn tracks cover algorithms in depth. Here you will learn what is distinctive about biological data, how to turn sequences into numbers, how to evaluate a model honestly, and how deep learning reads sequences. The most important theme is not an algorithm but a discipline: biological data can fool a model, and an honest evaluation is the only defense.

Four cards: sequences with labels, features, a model, and evaluation on held-out data, each with a small drawing.
Caption: the workflow is data, features, model, evaluation, and the last step decides whether to believe the first three.

What you will learn

  • The common kinds of machine-learning tasks in bioinformatics.
  • The standard workflow from labeled data to an evaluated model.
  • Why biological data cause special problems: small samples, imbalance, label noise and homology.
  • How the lessons in this chapter fit together.

Key terms

Supervised learning: learning a mapping from inputs to known labels, such as sequence to promoter or not.

Feature: a number describing an example, such as GC content or the count of a k-mer.

Training and test sets: data used to fit the model, and held-out data used to judge it.

Overfitting: fitting noise in the training set so well that performance on new data suffers.

Class imbalance: one class (often the interesting one) is much rarer than the other.

Kinds of tasks

Task Question Example in biology
Classification which category? Is this sequence a promoter? Is this variant pathogenic or benign?
Regression how much? Predict a gene's expression level from its regulatory DNA
Clustering which examples group together? Find cell types in single-cell data; group tumor profiles
Dimensionality reduction what are the main axes of variation? PCA of expression data
Structure prediction what shape or interaction? Predict a protein fold or a residue contact

Supervised tasks (the first two) need labels; clustering and dimensionality reduction do not. Biology is rich in unlabeled data, which is one reason self-supervised models trained on raw sequences have become so prominent: they learn from millions of sequences without any labels and can then be adapted to a small labeled task.

The standard workflow

  1. Define the question

What to predict? Label or number
Where do labels come from? Experiments, curation

A model is only as good as its labels

1 / 4

What makes biological data special

Many features, few samples. An RNA-seq study may have 20,000 genes (features) and 30 patients (samples). With more features than examples, many models can fit the training data perfectly by chance, and regularization or feature selection is essential.

Class imbalance. Disease-causing variants are rare among all variants; true binding sites are rare among all positions in a genome. A model that always predicts "no" can be 99% accurate and useless. The evaluation lesson shows how to measure what matters.

Noisy labels. Labels come from experiments or human curation that have errors. Clinical databases contain variants classified under older evidence. A model cannot be better than its labels, and can learn their mistakes.

Homology and data leakage. Biological sequences are related by evolution. If a protein and its close relative land in different sets, the test set is not independent and the score is inflated, because the model can recognize relatives rather than learn the underlying rule. This is the single most common way to publish a model that does not work in practice.

Confounders and batch effects. A model may learn which lab or sequencing machine produced a sample instead of the biology, because that is easier to see.

Ethics and fairness. Training data are not representative of all populations. Models trained mostly on one ancestry can perform worse on others, and models trained on personal genetic data raise privacy questions. Report who is in your data.

A cautionary story

Imagine a team that trains a model to recognize enhancers, stretches of DNA that boost the activity of a nearby gene. They collect 10,000 enhancers from a database as positives and sample 10,000 random genomic regions as negatives. Their model reaches 97% accuracy on a random test split, and they are delighted.

Then a colleague asks two questions. First: where did the positives come from? They were found by an experiment in a single cell line, so they are enriched in a few repeat families that happen to be active in that line. Second: where did the negatives come from? Random regions are mostly unremarkable, and they have different GC content and repeat content than the positives. A very simple model that only counts a few repeat-associated k-mers would already separate the two sets. The network did not learn what makes an enhancer; it learned how the two sampling procedures differ.

When the team evaluates on enhancers from a different cell type, with negatives matched for GC content and repeat content, accuracy falls to the low 60s. The story is not unusual. It shows the three questions you should ask of any published biological model: how were the positives and negatives chosen, are related examples kept together in the split, and does the result survive on data collected a different way?

Simple first, complex later

A good habit is to start with the simplest model that could possibly work, and to add complexity only when a stronger baseline fails. A threshold on GC content, a logistic regression on k-mer counts and a random forest are all quick to build and easy to interpret. If a deep neural network barely beats them, the extra complexity is probably not justified; if it beats them by a lot on a clean, leak-free split, then you have learned something real about the problem. Simple baselines also act as a check on your pipeline: if a model trained on shuffled labels still scores well, something is leaking.

The lessons that follow apply this attitude. You will first make sequences into numbers and fit a transparent model whose weights you can read, then measure it properly, and only then meet convolutional networks and language-model embeddings, which are powerful because they learn features instead of requiring you to design them.

What each lesson covers

Lesson What you will do
Sequence Features Count k-mers, one-hot encode, train a logistic regression and read its weights.
Evaluating Classifiers Build confusion matrices, ROC and precision-recall curves, and see data leakage in action.
Deep Learning for Sequences Train a convolution filter that discovers a motif, and meet language-model embeddings.
Chapter Review A checklist for building and judging biological models.

Try it

The first example is the simplest possible classifier: a threshold on GC content. The second plots the central picture of machine learning: as a model becomes more flexible, training error keeps falling while test error eventually rises.

Python A one-feature classifier

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Python Overfitting: training versus test error

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. Which is an example of a regression task in bioinformatics?

    Regression predicts a number; classification predicts a category.
  2. 2. Why is a 99% accuracy not impressive when only 1% of positions are true binding sites?

    With a rare positive class, the trivial all-negative prediction is highly accurate but useless.
  3. 3. What is data leakage in sequence modelling?

    Close relatives let the model recognize memorized examples instead of generalizing.
  4. 4. With 20,000 gene features and 30 samples, the main danger is:

    With far more features than samples, a model can fit noise perfectly; regularization helps.

Summary

  • Biological machine-learning tasks include classification, regression, clustering, dimensionality reduction and structure prediction.
  • The workflow is question and labels, features, honest split, fit, evaluate and interpret.
  • Biology adds special hazards: many features with few samples, class imbalance, noisy labels, homology leakage, confounders and unrepresentative data.
  • An honest evaluation is the main defense against fooling yourself.

Next: Sequence Features