AI & ML Quick Path Progress

All cheat sheets

Cheat sheet: choosing a machine learning algorithm

A first guess at what to try. Always compare on the same folds and the same metric.

Start simple

  • Linear or logistic regression: fast, explainable baseline.
  • Compare everything against it.

Tables of data

  • Gradient boosting usually wins.
  • A random forest is a robust default.
  • A single decision tree is easy to explain but overfits.
Three small decision trees, each trained on a different random re-sample. Trees 1 and 3 vote yes and tree 2 votes no. The forest answer is yes, two votes to one. Each tree sees a different random re-sample of the data Tree 1 question votes yes Tree 2 question votes no Tree 3 question votes yes Forest answer: yes (2 to 1) Many trees, one vote. Made-up example with three trees. A real forest has hundreds. Averaging many different trees steadies a model that one tree overfits.
A random forest trains many different trees and lets them vote. The three trees here are a made-up example.

Images, audio, free text

  • Neural networks usually win here (Part 4).
  • For text, a strong baseline is naive Bayes or a pretrained model.

Nearest neighbours

  • No training step: it keeps all points and lets the closest ones vote.
  • Slow on big data; scale the columns first.
A scatter of circles and squares with a new diamond-shaped point in the middle. A dashed circle around the new point contains its three nearest neighbours: two circles and one square. The two circles outvote the square, so the new point is labelled a circle. new point k-nearest neighbours, k = 3 1. Find the 3 closest known points (inside the dashed circle). 2. Let them vote: 2 circles, 1 square. 3. The new point gets the majority class: circle. No training step: it keeps all the points and is slow on big data. Made-up points in two dimensions. Circle = one class, square = the other.
k-nearest neighbours with k = 3: find the three closest known points and let them vote. There is no training step.

Support vector machines

  • Widest gap between classes; the setting C decides how many points may sit on the wrong side.
  • Needs scaled features; suits small and medium data.
Circles on one side and squares on the other, with a solid boundary line between them and two dashed lines marking the margin. The points closest to the line are circled and called support vectors. Text says a soft margin, set by C, lets some points sit on the wrong side. Support vector machine Many lines separate the two groups. The SVM picks the one with the widest gap (the margin). Circled points are the "support vectors": the ones closest to the line. Soft margin: setting C decides how many points may sit on the wrong side. Made-up points. Solid line = the boundary; dashed lines = the edges of the margin.
A support vector machine picks the boundary with the widest gap between the classes; the closest points are the support vectors.

Naive Bayes

  • A score per class: how common the class is times how likely each word is in it.
  • Treats words as independent clues: naive, but a fast text baseline.

No labels

  • k-means to find groups; PCA to compress; anomaly detection to find the odd ones out.
Three panels with the same ten points and two diamond-shaped centres. Panel 1: each point joins its nearest centre. Panel 2: each centre moves to the middle of its points. Panel 3: repeating until the groups stop changing. 1. Pick centres, assign each point joins its nearest centre 2. Move the centres to the middle of their points 3. Repeat until still the groups stop changing k-means with k = 2 (diamonds are the centres) Made-up points. The method needs no labels: it finds the groups from distances alone.
k-means assigns each point to its nearest centre, moves the centres to the middle of their points, and repeats. The points are made up.

Compare fairly

  • Same cross-validation folds, same metric.
  • Weigh accuracy against speed, memory and explainability.
  • Tune the best one or two only.