Supervised Models: Cheat Sheet
Assembled from the matching per-unit cheat-sheet slices. This is the single revision page for the whole topic - trees, KNN, neural networks and SVM.
Decision trees and ID3
- Entropy . A pure node gives 0; a balanced two-class node gives 1.
- Information .
- Gain .
- Play-Tennis worked numbers: ; gains are Outlook 0.247 (the root), Humidity 0.152, Windy 0.048, Temp 0.029.
- ID3: compute the gains, pick the highest, split, recurse - stopping when a node is pure. It is greedy with no backtracking.
- Hypothesis space = all decision trees, so it is complete. It keeps a single hypothesis, never backtracks, and uses all the examples at each step (which makes it noise-robust).
- Inductive bias (a preference bias): prefer shorter trees, and high-gain attributes near the root. Occam's razor.
- Overfitting: great on train, worse on test. Fix with pre-pruning or, better, post-pruning; choose the size with a validation set, a test, or MDL.
- Continuous attributes: turn into a Boolean , and pick the threshold - a midpoint where the class changes - that maximises gain.
Instance-based learning and KNN
- Lazy: store the data and do the work at query time, giving a rich local hypothesis. KNN is lazy.
- Eager: build the model upfront, giving a single global hypothesis. A decision tree is eager.
- KNN classifies by the nearest neighbours. Discrete targets take the mode, real-valued targets the mean.
- Euclidean distance .
- K must be odd, to avoid ties. K = 1 produces a Voronoi partition.
- Small K captures structure but is noisy; large K is noise-robust but needs more data. The elbow method picks K from the error-rate-versus-K plot.
- Weighted KNN: closer neighbours weigh more, with . Its inductive bias is "birds of a feather flock together".
- Complexity is .
Slow at query time, cursed by dimensionality, needs same-scale features, no easy way to pick the optimal K, and it struggles with imbalanced classes, outliers and missing values. The curse of dimensionality shrinks the influence radius as dimensions grow; mitigate it with attribute weighting or leave-one-out, and aim for roughly 5 instances per attribute.
Perceptron and gradient descent
- Perceptron: if , else 0. The bias is with , and is perpendicular to the decision boundary.
- It represents AND, OR, NAND, NOR - all linear. AND: , . OR: , .
- It cannot do XOR, which is not linearly separable, so a multilayer network is required.
- Perceptron training rule: .
- Minimise and update .
- small is slow; large overshoots. Either way gradient descent can settle in a local minimum.
Neural networks
- Layers: input (no computation) → hidden (the learning core, any number of them) → output. Number of layers = hidden layers + output layer.
- Activation adds non-linearity, applied to . Without it the network is just linear regression.
- Forward propagation: .
- Weight-matrix dimension = (units in the current layer) × (units in the next layer).
- Minimise the loss by the chain rule, working output → input.
- .
- , and .
- Overfitting fix: keep a validation set and retain the weights with the least validation error.
Activation functions
| Function | Range | Note |
|---|---|---|
Sigmoid 1/(1+e⁻ˣ) | (0, 1) | probability |
| Tanh | (−1, 1) | zero-centred |
ReLU max(0, x) | [0, ∞) | can "die" |
Leaky ReLU (αx for negative x) | ℝ | fixes dying ReLU |
Softmax eˣⁱ/Σeˣʲ | (0, 1), sums to 1 | multi-class output |
Vanishing and exploding gradients
- In a deep net : a per-layer scale above 1 explodes, below 1 vanishes. The gradients do the same.
- Fix with weight initialisation. is Xavier, for tanh; is He, for ReLU.
SVM
- SVM is a maximum-margin classifier. The planes are H0
w·x + b = 0, H1= +1, H2= −1, and the support vectors define the boundary. - The two class constraints combine into .
- Margin width .
- Primal: minimise subject to .
- Dual (Wolfe): maximise , subject to and . Then .
- KKT: every non-support-vector has ; only the support vectors have .
Kernels
- The dual touches the data only through a dot product, which licenses the kernel trick: without ever computing . A kernel is valid exactly when it is expressible as a dot product.
- Polynomial: .
- Gaussian / RBF: - the default, a similarity measure, effectively infinite dimensions.
- γ: high gives a tight boundary that overfits, low gives a smooth one. C: high punishes errors and overfits, low gives a soft margin that generalises.
Notes on the source
- Decision trees are supervised, not unsupervised, as one slide had it.
- The "salary / job-acceptance" information-gain arithmetic on the slides was internally inconsistent, so entropy and gain are taught here with the fully correct Play Tennis worked example instead.
- Everything above covers every slide topic in the Unit 1 folder and the Unit 2 folder (decks 13-24).
- Several SVM and backpropagation slides were equation-only images that do not extract as text; those derivations are reconstructed here from standard ML and match the slide flow.
- The "Lecture 22-23" video is the SVM recording, and its content corresponds to the 21-23 deck covered under SVM above.