Classification · Part 4
Recap how classifiers make predictions, then use perceptron geometry to understand the widest separating margin and a linear SVM.
Different methods use the same input features to choose a class.
Naive Bayes and logistic regression estimate class probabilities from the input features.
KNN looks at nearby training examples and uses their labels to predict.
Learn weights and a bias, then classify from the sign of their weighted score.
Part 1 used Naive Bayes and logistic regression to estimate how likely each class is for the given input.
Choose class 1, with estimated probability 0.55. The model assigns substantial probability to either class.
Choose class 1, with estimated probability 0.95. The model is more confident in this prediction.
Part 2 kept the labeled training data. At prediction time, KNN finds the K nearest examples and uses their labels.
Three neighbors have class 1.
Two neighbors have class 0.
Predict class 1.
The local class-1 fraction is 3/5 = 0.6.
Keep the observation’s input fixed during an update. Use its prediction error to change the weights.
Its feature values are the input. Its known class is the target.
Compute the current score, predict a class, then compare it with the target.
A mistake changes the weights and bias. Revisit the examples until a whole pass makes no mistakes.
The horizontal coordinate is feature 1. The vertical coordinate is feature 2.
The boundary contains every point satisfying .
Keep the feature weights fixed and change w₀. Watch the intercepts and the two prediction regions.
Use . Predict 1 when s ≥ 0 and 0 when s < 0.
The signed perpendicular distance is .
For the noisy AND problem, several lines classify every training point correctly. A linear Support Vector Machine (lSVM) chooses a separator by maximizing its distance from the nearest observations of both classes.
First inspect two lines with the same training accuracy.
Use the weight vector to measure the gap to the nearest points.
Maximize that gap while respecting the class constraints.
Compare the two lines and read the nearest-point clearance for each. A gold ring marks the selected point.
The score is the weighted sum of the input’s feature values plus the bias.
The sign tells us which side of the separator the point is on. The separator h contains exactly the points where s(x) = 0.
The vector 𝐰 is perpendicular to the separator. Moving along the separator leaves the score unchanged.
The bias w₀ moves the separator without changing its orientation.
The solid line is the separator. The dashed lines bound the margin and the arrow is perpendicular to them. A gold ring marks the selected point.
The separator stays at score 0. Scale the weights and bias together so the closest training point has a score of −1 or +1. Then draw a parallel line at each of those scores.
Each line joins points with the same score.
Each edge is 1/‖𝐰‖ plot units from the separator.
Move the solid line. When it separates both classes, the dashed lines mark scores −1 and +1. Select Fit max-margin to see the widest strip.
Multiply each score by its true class label to merge the two inequalities into one.
For yᵢ = +1, the score must reach +1. For yᵢ = −1, it must be at most −1.
A wider empty strip puts the separator farther from the nearest training points on each side.
A smaller nonzero weight norm gives a wider margin. Squaring and multiplying by ½ keeps the minimizing coefficients the same.
First compute the fitted score for the input. Its sign tells you which class to predict.
Try a point. Fix the fitted weights at ŵ₁ = 2 and ŵ₂ = 1, with bias ŵ₀ = −2.
At the hard-margin SVM fit, the closest training points touch the dashed edges. Support vectors are the points on those edges that determine the fitted separator.
With the score rule s(x) = 2x₁ − 4, a blue point at x₁ = 1.5 scores −1. Its true label is −1, so (−1) × (−1) = 1. It touches the blue edge.
A blue point at x₁ = 1 scores −2, so (−1) × (−2) = 2. It is farther from the separator and does not limit the width.
In the dual formulation, a hard-margin support vector has a positive multiplier aᵢ and lies on its class’s edge. A point beyond the edge has aᵢ = 0.
Hard margin asks every point to stay on or beyond its own margin edge. If the classes overlap, that may be impossible. A soft-margin SVM allows points inside the margin or on the wrong side, and charges for those violations.
In the hard-margin rule the signed score must reach 1. A point with signed score 0.6 falls short by 0.4, so its smallest allowed slack is 0.4.
The first term favors a wider margin. The second charges C for each unit of slack. A larger C puts more weight on avoiding violations.
Read chapters 4 and 7 for linear discriminants, perceptron learning, and support vector machines.
The separator has score 0. Its margin edges have scores −1 and +1.
Choose the widest strip with every training point on or beyond its class’s edge. Support vectors anchor the strip.
Allow violations and use C to set their cost.
Lecture 14 · Classification · Part 4