0:00Intro: MOFUSA Tech Academy
Welcome to MOFUSA Tech Academy. Beyond learning, towards mastery.
0:09Which line is best?
Here are eight Brightcart customers. Green ones stayed and red ones left. And here are three different lines, each separating them perfectly. Every one of them scores one hundred percent on this data. So which line is best? This one hugs the green customers, this one hugs the red, and this one runs right down the middle. Now a new customer arrives, close to the edge. The line that hugged the green group gets them wrong. The middle line gets them right. Intuitively, the best boundary is the one with the most breathing room on both sides, the widest street between the two groups.
That intuition is the heart of the support vector machine, one of the most elegant ideas in machine learning. Season One, Module Four, final stop: support vector machines.
1:06The widest street
Here's the idea made precise. Imagine a street running between the two classes, with a kerb on each side. We want the widest possible street that keeps all the green customers on one side and all the red customers on the other. Let's widen it. The street grows until its kerbs touch customers on both sides. Here, a green customer with three complaints and two late deliveries, and a red customer with six complaints and five late deliveries. They're pinning the street in place. The widest street runs along the line where complaints plus late deliveries equals eight, with kerbs at five and eleven.
Its width is about four point two four. That centre line is the maximum-margin classifier.
1:54The maths of the margin
Let's write it down. Optional deep dive; the plain-words version comes right after. The boundary is where w dot x plus b equals zero, the same linear score as in logistic regression. The kerbs are where that score equals plus one and minus one. The weight vector w points straight across the street. A little geometry shows the street's width is two divided by the length of w. For Brightcart, w is one third, one third. Its length is about zero point four seven one, so the width is about four point two four. And we can check that the two pinned customers sit exactly on the kerbs: plugging in the green one gives minus one, and the red one gives plus one.
So the training problem becomes: make w as short as possible, which makes the street as wide as possible, while keeping every customer on the correct side of its kerb. In plain words: find the widest street that still separates the classes.
3:00Support vectors
Here's a striking property. Move a customer who's far from the street, or delete them entirely, and nothing changes. The street stays exactly where it is. But nudge one of the pinned customers, and the whole street shifts. The final model depends only on the points touching the kerbs. Those are the support vectors, and they give the method its name. Everything else could be thrown away after training. It's an elegant contrast with logistic regression, where every single point has some influence on the line.
3:35Soft margins and C
Real customers don't line up so neatly. Here, one customer who left looks just like the ones who stayed. No straight street can separate them perfectly, and a strict, hard margin is simply impossible. The fix is a soft margin. We allow some customers to step onto the street, or even across it, but each one pays a penalty for how far it intrudes. A setting called C controls how expensive those violations are. With a small C, violations are cheap, so the model prefers a wide, relaxed street and ignores a few awkward points.
With a large C, violations are expensive, so the street narrows and twists to classify as many points as possible, risking overfitting. This penalty is exactly the hinge loss from our cost-functions briefing. Customers safely beyond their kerb cost nothing. Halfway into the street costs zero point five. On the centre line costs one. And on the wrong side, it keeps growing. On the curved churn pattern from last episode, a tiny C scores about eighty-one percent on test data, C equals one about ninety-one, and very large C's drop back to between eighty-eight and ninety percent, even as training accuracy keeps creeping up.
The overfitting curve, once again.
5:01The kernel trick: lift, slice, drop
So far, SVMs draw straight streets. But the most famous part of the method is how it draws curved ones. Look at these customers on a line. The ones who left are at both ends, and the ones who stayed are in the middle. No single cut point separates them. Now try something. Lift each point up to a height equal to x squared. They land on a parabola. And now a straight horizontal line at height four separates them perfectly. Drop back down to the original line, and that straight cut becomes two boundaries, at minus two and plus two.
The same thing works in two dimensions. A green cluster surrounded by a red ring can't be split by a straight line. Lift every point by its squared distance from the centre, and the data forms a bowl. A flat plane slices it cleanly. Project back down, and the boundary is a circle. Here's the clever part, called the kernel trick. When you solve the SVM's optimisation problem, the data only ever appears inside dot products between pairs of points. A kernel is a function that computes the dot product in the lifted space directly, without ever actually building the lifted coordinates.
So we get the power of a huge feature space at the cost of a simple formula.
6:25The RBF kernel and gamma
The most popular kernel is the radial basis function, or R-B-F kernel. It measures the similarity of two points as e to the minus gamma times their squared distance: one for identical points, fading towards zero as they move apart. Behind the scenes, it corresponds to a lifted space with infinitely many dimensions, which the kernel trick lets us use without ever computing it. A nice way to picture it: every support vector raises a little bump or digs a little dip in a landscape, and the decision boundary runs along the contour where the bumps and dips balance out.
Gamma sets the width of the bumps. A small gamma gives wide, gentle bumps and smooth boundaries. A large gamma gives narrow spikes around individual points, and you're back to memorising. On the curved churn pattern, a straight-line SVM scores eighty-four percent. The R-B-F version bends its boundary to follow the curve: ninety-one percent. And because the R-B-F kernel is built on distances, scaling the features first is essential. C and gamma are tuned together, with cross-validation.
7:42Where SVMs fit today
Support vector machines were among the most successful methods of the late nineties and two thousands, from text classification to recognising handwriting. They still shine with medium-sized datasets and many features, like text represented by thousands of word counts. Their limits: training gets slow on very large datasets, they don't naturally produce probabilities, and with kernels they're harder to explain. There's also a regression version, support vector regression, which fits a tube around the data and ignores errors smaller than the tube's width.
And notice how many of their ideas live on: margins, hinge loss, kernels as measures of similarity. We'll recognise them again later in the course.
8:30Try it yourself: classify a new customer
A new customer has filed five complaints and suffered four late deliveries. Which side of the street are they on, and how confident should we be? Pause and compute the score: a third of five, plus a third of four, minus eight thirds.
Nine thirds minus eight thirds: plus a third. Positive, so the SVM places them on the "leaving" side. But the score is less than one, which means they're inside the street, between the kerbs. That's a borderline case. The SVM's score doubles as a measure of confidence: far beyond a kerb means confident; on the street means uncertain. This customer might deserve a closer look, rather than an automatic decision.
9:20More than two classes
SVMs are naturally two-class methods, so how do they handle three ticket types? Two common strategies. One-versus-rest: train one SVM to separate delivery tickets from everything else, another for refunds, another for damage, and choose the class whose SVM is most confident. Or one-versus-one: train an SVM for every pair of classes and let them vote. Libraries do this automatically. Just remember that SVM scores aren't probabilities unless you calibrate them.
9:56SVM vs logistic regression
How does a linear SVM differ from logistic regression? Both draw a straight boundary. The difference is the loss. The hinge loss becomes exactly zero once a point is safely beyond its kerb, so only the points near the boundary, the support vectors, matter. Log loss never quite reaches zero, so every point keeps a little influence, and the model produces probabilities. In practice, their linear versions often perform similarly. Logistic regression is the natural choice when you need probabilities and simple explanations; SVMs shine with kernels and high-dimensional data.
10:38Choosing a kernel and its settings
Which kernel should you use? When you already have many features, like word counts for text, start with a linear kernel; the data is often separable enough already. For a few features with curved boundaries, use the R-B-F kernel, and tune C and gamma together. A grid search with cross-validation produces a heatmap of accuracy, with a bright sweet spot where both are well chosen. Polynomial kernels can capture known interactions, but they're less common. And always scale your features first.
11:15Support vector regression
The margin idea also works for regression. Support vector regression fits a line, or a curve with a kernel, surrounded by a tube of a chosen width. Any point inside the tube costs nothing; only points outside it are penalised, and only by how far they stick out. For delivery predictions where being within two minutes is good enough, that's a natural fit: small errors are ignored, and the model focuses on the big misses.
11:46The legacy of SVMs
Even where deep learning has taken over, the ideas behind SVMs live on. Margins appear in modern training objectives that push similar items together and different ones apart. The hinge loss shows up in ranking problems. And kernels, as measures of similarity between data points, are cousins of the dot-product similarity at the heart of attention, which you'll meet in Season Two. Understanding SVMs makes those later ideas feel familiar.
12:18Myth vs Fact: the kernel trick
Myth: the kernel trick secretly computes millions of new features. Fact: it never builds them at all. The kernel computes the dot product those features would have, directly from the original points. For the R-B-F kernel, the lifted space is infinite. No computer could ever store it, and it doesn't need to.
12:40Recap
Let's recap. A support vector machine chooses the separating boundary with the widest margin. The width is two over the length of w, and only the support vectors on the kerbs decide it. Soft margins allow some violations, with C setting their price, which is the hinge loss. And the kernel trick computes dot products in a lifted space, so straight streets there become curved boundaries here. The R-B-F kernel is the most popular, with gamma setting how local it is. One sentence to remember: the widest street wins, and kernels let the street curve.
13:18Next: unsupervised learning and clustering
Mission complete. Brightcart's boundary has the most breathing room possible: the line where complaints plus late deliveries equals eight. And for curved patterns, the kernel trick bends the boundary to fit. And with that, Module Four, classification, is complete: logistic regression, honest metrics, neighbours, Bayes, trees, forests, boosting and support vector machines. A complete classic toolkit. Next, we enter a new world. No labels at all. No "stayed" or "left". Just data. Can a machine discover structure on its own, like the natural groups among Brightcart's customers?
Welcome to unsupervised learning, starting with clustering. See you on the map.