Fisher draws one line by averaging every point. The support vector machine draws the widest street between two classes, and only the points on its kerbs decide where it runs.
Learn how a classifier turns a cloud of labelled signals into a line, why Fisher’s answer is an eigenvector problem, and why the margin gives a sturdier line.
Pick a method, then drag the stray blue point toward the red cluster. Watch which lines swing and which stay still. Then we build, piece by piece, the whole lecture: the ratio Fisher maximizes, the algebra that solves it, Gaussians and stationary signals, and the margin that leads to the support vector machine.
You need a little linear algebra (a vector, a dot product, a matrix times a vector) and a feel for averages and spread. We build the rest from zero.
Based on Lecture 9 of Stanford EE269: Signal Processing for Machine Learning, taught by Mert Pilanci. Read the course’s own Lecture 9 slides and the slides page. Every picture and device here is our own.
Toy data we made up: 8 red points, 8 blue points and one stray blue point that slides from far behind the blue cluster to the middle of the red one. Fisher’s line is perpendicular to P−1(μ1 − μ2) and passes halfway between the two projected means. The SVM lines are solved live in your browser, with C = 10 for the soft margin, as in the lecture’s soft-margin formula.
Chapter 0
See why telling two kinds of signal apart needs a rule, and why estimating the rule from few samples is shaky
A roaster holds a bean under a row of chemical gas sensors. Each sensor reads one number as the aroma drifts past. Eight sensors give eight numbers. Is this bean Arabica or Robusta?
Those eight numbers are a feature vector: one list of measurements that stands for one thing. Think of it as a point in space, with one axis per sensor. A bean is a dot. Many beans of one kind form a cloud of dots.
A classifier is a rule that takes a new dot and answers with a label. The simplest rule is a straight cut through the space. Dots on one side get one label, dots on the other side get the other. This lecture asks one question: where should the cut go?
To describe a cloud we use two summaries. The mean is where the cloud is centred: add up the dots and divide by how many. The covariance is the cloud’s shape: how far it spreads along each axis, and whether two axes rise and fall together.
The lecture opens with a recap. Suppose x1 to xn are independent draws from a Gaussian (the bell-shaped cloud) with mean μ and covariance Σ. The maximum likelihood estimates are plain averages.
A worked case with two sensors and three dots, (1, 2), (3, 3) and (5, 7). The mean is (3, 4). The offsets are (−2, −2), (0, −1) and (2, 3). Entry (1, 1) is (4 + 0 + 4)/3 = 2.67. Entry (2, 2) is (4 + 1 + 9)/3 = 4.67. Entry (1, 2) is (4 + 0 + 6)/3 = 3.33. The positive 3.33 says the two sensors rise together.
With few dots, the covariance is noisy. The lecture offers a fix, the regularized covariance: keep the spreads on the diagonal, and shrink the shared entries off it.
Σ̂ = (1 − α) diag(ΣML) + α ΣML
Here α is a dial from 0 to 1. At α = 1 you trust the data fully. At α = 0 you keep only each sensor’s own spread and assume the sensors are unrelated. Every dot in between is a blend. The slide on stability shows why you want one. It draws the covariance estimated from many 3-sample subsets of one dataset, and the ellipses disagree wildly.
The thick teal ellipse is the true cloud. Each thin ellipse is estimated from just 3 fresh dots. Lower α to shrink the estimates toward a safer shape, then press Redraw.
Illustrative: the true covariance is [[2.0, 0.8], [0.8, 1.5]], and each ellipse is the 90% contour of an estimate drawn at the true centre. The numbers are computed live from seeded random samples.
Shrinking pulls every estimate toward a safer shape, but it also pulls away from real correlation, so it helps less than you might hope on this cloud. Three dots simply carry little information. That is the first lesson of the chapter: the fewer the dots, the less you should trust a rich model.
Now count what each method must learn. LDA (linear discriminant analysis) gives each of K classes its own mean, but shares one covariance. That is Kn means plus n(n + 1)/2 covariance entries. QDA (quadratic discriminant analysis) gives each class its own covariance, which costs K times as many.
The covariance table is symmetric, so only its upper half counts: n(n + 1)/2 entries. The slide writes this as n² + n over 2. For 8 sensors that is 36. For 200 spectral bands it is 20,100.
Bars use a log scale: each gridline is ten times the last. Slide the three numbers and compare what the model must learn with what you have.
The counts are exact: LDA has Kn + n(n + 1)/2 unknowns, QDA has Kn + K n(n + 1)/2. The sample numbers are yours to set.
Look at the 200-band case. Five classes and 40 dots each give 200 dots, but LDA already needs 21,100 numbers. The estimate is under-determined: many different covariances fit the dots equally well. This pressure drives the whole lecture. We want a rule with few unknowns, and a rule that does not depend on a fragile covariance estimate.
The road has two halves. First we squeeze the classes onto a few well-chosen directions, which is Fisher’s idea. Then we drop the cloud model entirely and fit only the boundary, which is the support vector machine.
Chapter 1
Cast a shadow of the data onto one line, and choose the line where the two classes’ shadows barely overlap
Hold two bunches of flowers in front of a lamp, and look at their shadows on a wall. From one angle the shadows pile on top of each other. Turn the lamp a little and the two shadows pull apart. You never moved the flowers. You only chose where to look from.
That is Fisher’s idea. Your data has many sensors, so many axes. Squash it onto one axis, and pick the axis that keeps the classes apart. Then a single threshold on that axis is your classifier.
Choose a direction, written as a vector a. The shadow of a dot x on that direction is one number: y = aTx. This is a projection: multiply each sensor by a weight and add. It turns a list of n numbers into one.
Now describe each class by what its shadows look like. Let μk be the mean of class k and Σk its covariance, as in Chapter 0. The shadows of class k have a mean βk and a variance σk² (the average squared distance from that mean). Both are expectations: averages over everything the class can produce.
Two shadows are well separated when their centres are far apart, and each one is narrow. Fisher turns that into one number. The distance between the centres is squared, and divided by the combined spread.
Take two classes in the plane, with means μ1 = (4, 2) and μ2 = (0, 0). Give both classes the identity covariance: a round cloud of spread 1 in every direction.
Try a = (1, 0), a look along the x axis. The shadow centres are β1 = 4 and β2 = 0, so the gap is 4. The variances are 1 and 1. Then J = 16 / 2 = 8.
Try a = (0, 1). The centres are 2 and 0. J = 4 / 2 = 2. A poor view, with the shadows heavily mixed.
Try the direction of the gap itself, a = (4, 2)/√20. The gap is the length of (4, 2), which is √20 = 4.47. So J = 20 / 2 = 10. This is the best view, because round clouds spread the same in every direction, and only the gap matters.
Top: two clouds of dots and your projection line. Bottom: the shadows on that line, with a bell curve for each class. Turn the angle until the bells part, or press the snap button.
Toy data: 40 seeded dots per class, drawn with the same elongated covariance and means 3.6 apart along the x axis. J and the best angle are computed from these 80 dots. The best angle is the one Chapter 2 derives in closed form.
The shadows are nearest to apart at one special angle, and it is not along the line joining the two centres. The clouds are stretched, and the best view leans away from the stretch. Distance between centres is not enough. You must also weigh the spread.
How do βk and σk² depend on a? The mean of a sum is the sum of the means, so βk = E[aTx] = aTμk. For the spread, start from the definition and expand.
σk² = E[(aT(x − μk))²] = E[aT(x − μk)(x − μk)Ta] = aTΣka
A number squared is that number times itself, and aTv equals vTa, so the square becomes a sandwich around the covariance. Now put both pieces into J.
J(a) = (aT(μ1 − μ2))² / aT(Σ1 + Σ2)a = aTQa / aTPa
with Q = (μ1 − μ2)(μ1 − μ2)T and P = Σ1 + Σ2. Q captures the gap between centres, and P the combined spread. Both are n by n tables, and a appears twice in each fraction. That shape, a vector, a matrix and the vector again, is a quadratic form. Chapter 2 shows how to maximize a ratio of two of them.
One more fact. Double a, and the top and bottom of J both grow four times. The score does not change. Only the direction of a matters, never its length. We are free to fix its length.
Chapter 2
Solve Fisher’s ratio exactly, first with one matrix, then with two, using eigenvectors and a change of view
You have a slider that turns a direction around a circle. A score rises and falls as you turn it. Somewhere it peaks. Can you find the peak without turning the slider at all? For ratios of quadratic forms, yes. The answer is an eigenvector.
Start with the simpler problem on slides 10 to 12: maximize aTQa / aTa. The bottom is just the squared length of a, so this asks: among all directions, which one does Q stretch most?
An eigenvector of Q is a direction that Q only stretches, never turns: Qu = λu. The stretch factor λ is its eigenvalue. A symmetric matrix has a full set of perpendicular eigenvectors, collected as the columns of U, and we write Q = UΛUT, with the eigenvalues down the diagonal of Λ. This is the eigenvalue decomposition.
Now change view. Let b = UTa, so a = Ub. The matrix U only rotates, so it keeps lengths. Substitute.
That is the whole proof. An average of numbers is at most the biggest of them. The average equals λ1, the largest eigenvalue, only when all the weight sits on b1. That means b = (1, 0, …, 0), so a = Ub is the first column of U: the top eigenvector u1. The maximum value is λ1.
A worked case. Take Q = [[3, 1], [1, 2]]. Its eigenvalues solve λ² − 5λ + 5 = 0, which gives λ = (5 ± √5)/2 = 3.618 and 1.382. The top eigenvector is (0.851, 0.526). Check three directions. a = (1, 0) gives 3. a = (0, 1) gives 2. a = (0.851, 0.526) gives 3.618. Turn the dial below and see the peak.
Top: a unit vector a on a circle, and the eigen axes of Q. Bottom: the score aTQa against the angle. It never leaves the band between the two eigenvalues.
Q = [[3, 1], [1, 2]] is a small example we chose. Its eigenvalues, 3.618 and 1.382, are computed exactly in your browser.
Fisher’s ratio has a different bottom, aTPa, where P is the combined spread. Slides 13 to 17 solve this. The trick is to find one change of view that tidies both matrices together.
The simultaneous diagonalization theorem says: if P and Q are symmetric and P is positive definite (every direction has positive spread), then some matrix V gives VTPV = I and VTQV = Λ, a diagonal table. The columns of V satisfy Qvi = λiPvi, called the generalized eigenvalue equation.
The proof builds V in two steps (slide 15). First, take the eigenvalue decomposition P = UPΛPUPT. Set V′ = UPΛP−1/2. This whitens P: it divides each axis by its spread, so V′TPV′ = I. Second, V′TQV′ is symmetric, so it has its own decomposition U′Λ′U′T. Set V = V′U′. The extra rotation U′ keeps P at the identity and diagonalizes Q.
Now substitute a = Vb. The ratio becomes bTΛb / bTb, the single-matrix problem again. So the best a is v1, the top generalized eigenvector, and the best score is the top generalized eigenvalue λ1.
Left: a-space, where the allowed directions form the ellipse aTPa = 1. Right: whitened b-space, where they form a plain circle. The purple arrow is the whitened gap. Turn b until it lines up with the arrow.
Toy numbers we chose: P = [[3, 1.2], [1.2, 1]] and gap d = (3, 1), so Q = ddT. The whitening matrix P−1/2 is computed live from the eigen decomposition of P.
For Fisher, Q = ddT with d = μ1 − μ2. The equation Qa = λPa becomes P−1ddTa = λa. Here dTa is just one number, so the left side is P−1d times a number. Therefore a is a multiple of P−1d.
a = P−1(μ1 − μ2) / ||P−1(μ1 − μ2)||2
Check it with numbers. Let P = diag(4, 1) and d = (4, 2). Then P−1d = (1, 2), and its score is (dTa)² / aTPa = 8² / 8 = 8. Compare a = (1, 0): 16 / 4 = 4. Compare a = (0, 1): 4 / 1 = 4. Compare the plain gap direction (4, 2): 400 / 68 = 5.88. Only P−1d reaches 8, which equals dTP−1d = 16/4 + 4/1.
In code, this is one linear solve: a = np.linalg.solve(P, mu1 - mu2). No search, no iteration.
Chapter 3
Project K classes onto several directions at once, and compare two scatter matrices with one ratio of volumes
Now the roaster has five kinds of bean, not two. One shadow line is not enough: five clouds can hide behind each other on any single line. We need a few lines, a flat sheet to cast shadows on. Fisher’s idea must grow from one direction to several.
Suppose class k has Nk dots xj. Its mean is μk, and the mean of all dots together is μ. The lecture defines the scatter of a class as the covariance summed rather than averaged:
Sk = Σj in class k (xj − μk)(xj − μk)T
The within-class scatter SW adds these over all classes. It measures how wide each cloud is around its own centre. The between-class scatter SB measures how far the class centres sit from the grand centre, weighted by class size.
With two classes, SB collapses to a multiple of the gap table Q from Chapter 1. Many classes generalize it.
Now project with a table A that has n rows and m columns, so y = ATx turns each n-number dot into m numbers. The means follow the same rule as before: the new mean of class k is ATμk. For the scatter, expand each offset (ATx − ATμk) = AT(x − μk), and the scatter picks up an A on each side.
S̃k = ATSkA, S̃W = ATSWA, S̃B = ATSBA
For one direction (m = 1) these were two numbers, and we divided them. Now they are two m by m tables. You cannot divide a table by a table. The lecture asks: what is the right objective?
A determinant turns a table into one number: the volume of the box the table makes out of a unit cube. A wide table gives a big volume, a narrow one a small volume. So the lecture compares the two volumes:
J(A) = |ATSBA| / |ATSWA|
The top says how big the spread of centres is, in the shadow space. The bottom says how big the spread inside the clouds is. A large ratio means centres are far apart compared with the clouds. An alternative, trace[(ATSWA)−1(ATSBA)], gives the same answer.
The solution is the same trick as Chapter 2. The columns of the best A satisfy SBai = λiSWai. They are the eigenvectors of SW−1SB, taken in order of the largest eigenvalues. With m columns, J equals the product of the top m eigenvalues.
Take three classes in the plane, each with 10 dots, and each with the identity covariance. Then Sk = 10 I and SW = 30 I. Let the centres be (−2, 0), (2, 0) and (0, 3). The grand mean is (0, 1).
The offsets from the grand mean are (−2, −1), (2, −1) and (0, 2). Each outer product times 10 gives [[40, 20], [20, 10]], [[40, −20], [−20, 10]] and [[0, 0], [0, 40]]. Add them: SB = [[80, 0], [0, 60]].
Then SW−1SB = diag(80/30, 60/30) = diag(2.67, 2). The eigenvalues are 2.67 and 2. One direction gives J = 2.67. Both directions give J = 2.67 × 2 = 5.33, which matches |SB| / |SW| = 4800 / 900.
Solid purple: the best direction. Dashed purple: the second. Below: the shadows on the best direction only. Pull the class centres apart or push them together.
Toy data: 3 classes of 30 seeded dots with the same shape of cloud and centres at (−2, −1), (2, −1) and (0, 2.2), scaled by your slider. SW and SB are computed from the dots, and the eigenvalues of SW−1SB live in your browser.
Watch the eigenvalues as you slide. Both grow with the square of the centre spread, since SB does. The clouds do not change, so SW stays put. And the first direction always carries more separation than the second.
One rule limits the whole method. SB is built from K offsets that all average to zero, so it has rank at most K − 1. Only K − 1 eigenvalues can be above zero. Five bean types give at most four useful directions, however many sensors you have. That is a squeeze from a long feature vector down to a handful of numbers, with the class separation kept.
Chapter 4
Read a covariance as an ellipse, whiten it to a circle, and compute how much room a cloud really takes
Sprinkle a handful of salt on a table and look at where the grains land. Most fall near the middle. A few stray far out. Squint, and the pile looks like a soft oval. A Gaussian cloud is that oval, and its covariance is the recipe for the oval’s size and tilt.
The multivariate Gaussian gives every point x a density (how crowded the cloud is at x). The slide writes it for n numbers per dot:
All the shape lives in that quadratic form. A contour is the set of points where it holds one fixed value. Every point on one contour is equally dense. The contours are ellipses in the plane, and ellipsoids in higher dimensions. Their axes point along the eigenvectors of Σ, and the axis lengths scale with the square roots of its eigenvalues.
Chapter 2 whitened a matrix. Here it whitens a cloud. Subtract the centre, then multiply by Σ−1/2:
z = Σ−1/2(x − μ) so that z ~ N(0, I)
The tilted, stretched oval becomes a round cloud of spread 1 in every direction. The squared length of z is exactly the quadratic form above, written as zTz. This squared Mahalanobis distance says how many “spreads” a point is from the centre, and it respects the cloud’s tilt.
Pick a chance α, say 0.1. We want the smallest region that holds 1 − α of the cloud, so 90%. Because the cloud is densest at the centre, the smallest region is the ellipse bounded by a contour.
In whitened space this is a circle, and we need its radius r. In two dimensions, z1² + z2² follows a chi-square distribution with 2 degrees of freedom. It has a neat tail: the chance that zTz exceeds r² is e−r²/2. Set this equal to α and solve: r² = −2 ln α.
For α = 0.1 this gives r² = 4.61. For α = 0.01 it gives 9.21. These are the two percentiles on the slide, written χ²2(0.1) and χ²2(0.01). Now the area. The circle of radius r has area πr². Undoing the whitening multiplies areas by |Σ|1/2. The slide writes area = π χ²2(α) σ1σ2, which holds when the two numbers are uncorrelated. With correlation ρ, the factor is |Σ|1/2 = σ1σ2√(1 − ρ²).
A worked case: σ1 = 2, σ2 = 1, no correlation. The 90% ellipse has area π × 4.61 × 2 = 29.0. The 99% ellipse has area π × 9.21 × 2 = 57.9. Doubling the confidence from 90% to 99% doubles the area. Try other cases below.
1,000 dots from one Gaussian, and the ellipse that should hold most of them. Change the spreads and the correlation, pick 90% or 99%, then press Whiten to see the same dots in z-space.
The 1,000 dots are seeded draws. The radius comes from r² = −2 ln α, which is exact for two dimensions. The count of dots inside is real, so it wobbles a little around 90% or 99%.
Notice what whitening does to the count. The same dots sit inside the circle as sat inside the ellipse, whatever you set. Whitening reshapes the space but changes no one’s membership.
The slide ends with the general rule. In n dimensions the smallest region holding 1 − α is an ellipsoid. Its volume is the volume of the unit ball, times rn, times |Σ|1/2, with r² = χ²n(α).
volume = [2πn/2 / (n Γ(n/2))] · (χ²n(α))n/2 · |Σ|1/2
The bracket is the volume of a unit ball. Check it. For n = 2 it gives 2π / (2 × 1) = π, the area of a unit circle. For n = 3 it gives 2π1.5 / (3 × 0.886) = 4.19, which is 4π/3, the unit sphere. (We read the slide’s factor as 2πn/2; it agrees with both checks.)
Why does a lecture on classifiers stop for this? Fisher and LDA assume each class is a Gaussian cloud. Knowing what a Gaussian looks like, and how much space it fills, tells you when that story is believable.
Chapter 5
Watch Fisher’s projection sort smells and satellite pixels, and see why a lamp’s brightness is the enemy
Two real signals now. The first is smell. Five kinds of coffee bean were presented to an array of chemical gas sensors, and each bean left a trace on every sensor. The second is light. A satellite looks down at a field, a lake and a car park, and records how brightly each patch shines in hundreds of colours.
On the lecture’s coffee-bean slide, the top picture is a set of time series: one wavy trace per sensor as the aroma arrives and fades. Summarize each trace by a few numbers and a bean becomes a feature vector, as in Chapter 0. The bottom picture is a 3D scatter in which the five kinds form separate clusters.
That 3D scatter is Fisher’s method at work. Five classes allow at most K − 1 = 4 useful directions (Chapter 3). The slide keeps three of them as axes and the five kinds of bean fall apart into groups. Many sensors, three numbers, five clusters.
The second application needs one idea from signal processing. A spectrum is how much light a surface returns at each wavelength, from blue through red into the infrared. Plot it and you have a signal: one value per band, in order. A hyperspectral camera records a whole spectrum for every pixel, so the picture is a stack of images, one per band, called a cube.
The lecture shows the Hyperion imaging spectrometer on the EO-1 satellite, with 200 bands. A pixel of grass reflects little red light and a lot of near-infrared. Water returns little at all. Bare soil rises gently. These curves are signatures, and a classifier must tell them apart pixel by pixel.
The trouble is the two things from Chapter 0. First, 200 bands means 20,100 covariance entries per class, so the within-class scatter SW may be nearly singular, and you add a small ridge or shrink the covariance. Second, sunlight is not constant. A sunlit pixel and a shadowed pixel of the same grass have the same shape of spectrum, but one is brighter. That brightness spreads each class cloud along one long line.
Fisher handles it well. The brightness swing makes SW large along the “all bands up together” direction. Fisher’s weights are P−1d, so they push little weight along that direction, and they lean on band differences that brightness does not touch. The method discovers the invariance without being told.
A two-band case shows how. Grass reads (0.1, 0.5) in bands 1 and 2, and soil reads (0.2, 0.3). Scale both by a brightness b between 0.7 and 1.3. Band 2 alone is a poor guide: grass spans 0.35 to 0.65, soil spans 0.21 to 0.39, and the two ranges overlap. Now take the weighted sum with a = (−3, 1). Grass gives −0.3 + 0.5 = 0.2 times b. Soil gives −0.6 + 0.3 = −0.3 times b. Grass is always positive and soil always negative, whatever b is. One threshold at zero separates them. The weights cancelled the lamp.
Try it. The device below makes three toy materials with 24 bands, then scales each pixel by a random brightness and adds noise. Compare two raw bands with the two Fisher directions.
Top: the mean spectrum of each toy material. Bottom left: every pixel plotted by just two raw bands (marked on the spectra). Bottom right: the same pixels on the two Fisher directions. Raise the noise.
Illustrative, not the lecture’s data: 3 made-up materials, 24 bands, 30 pixels each, with a random brightness factor (spread 0.35) on every pixel. Accuracy is nearest class mean on the training pixels, which flatters both views equally. Fisher uses a tiny ridge so SW can be inverted.
At low noise, the two raw bands already split water from the rest, but grass and soil smear along the brightness line. The Fisher view pulls all three into separate blobs. As noise rises, both views fall, yet Fisher falls later, because it averages over many bands.
One honest limit: Fisher only projects. After projecting, you still need a rule to assign a pixel to a class, such as the nearest class mean in the shadow space. Fisher also assumes that a flat sheet can keep the classes apart. Chapter 6 shows when it cannot.
Chapter 6
Meet the shapes a flat cut cannot separate, then see how quadratic rules and signals that repeat in time rescue the method
A target: a small round patch of one colour, ringed by a wide band of another. Try to split it with a ruler. Wherever you lay the ruler, half of one colour ends up on the wrong side. No straight line can do it.
The lecture’s “problems with linear discrimination” slides show three. Classes can sit as a ring around another class. They can curl round each other like two crescents. Or they can cross, like two ellipses laid in an X. In all three, the class means nearly coincide, so Fisher’s gap d is close to zero. The line has nothing to grip.
The slide with two concentric rings of dots has a second picture beside it: the same dots in three dimensions, where one class sits high and the other low. That is the escape. Add a feature that is a curve of the old ones, and a flat cut in the bigger space becomes a curved cut in the old one.
Left: the dots, with wrong answers crossed in red. Right: the shadows of the dots on Fisher’s direction, with the cut as a vertical line. Choose a shape, then switch on the extra feature.
Toy data: 80 seeded dots per class. The classifier is Fisher’s direction with the cut halfway between the two shadow means. Accuracy is on these same dots. The extra features are our choice, a preview of kernels in a later lecture.
A single added number lifts the score from about 60% to between 86% and 100%, depending on the shape. The classifier is still linear. Only the space changed.
A second escape keeps the original space but lets the boundary bend. Assume each class k is a Gaussian with its own centre μk and shape Σk, and a prior πk (how common the class is). Score each class by log(πk × density). Expand the logarithm of the Gaussian density from Chapter 4 and you get the lecture’s quadratic discriminant:
If all classes share one Σ, the bend Wk is the same for every class and cancels when you compare scores. What remains is linear: that is LDA. With separate shapes the cut curves: QDA. The price is the one from Chapter 0. QDA has K times more covariance numbers to learn.
Now signals in time. A stationary signal has statistics that do not change if you slide the clock: hiss, hum, steady engine noise. For such a signal the covariance between sample k and sample l depends only on the gap k − l, called the lag. So Σkl = r[k − l], and one list of numbers fills the whole table. A table with this constant-diagonal pattern is called Toeplitz.
You estimate the list by averaging products at each lag: r[k] = Σn (x[n] − μ)(x[n + k] − μ). For 200 samples this means 200 numbers instead of 20,100.
The Fourier transform cuts it further. The slide says: apply y = Fx, and every Σk turns into a diagonal table, FΣFH = diagonal. In the frequency basis, different frequencies stop being correlated with each other. You only estimate the diagonal, which is the power spectrum: how much energy the class has at each frequency. (The match is exact for tables that wrap around, and close for long signals.)
A signal that remembers its past: each sample is correlated with its neighbours. Left: the 16 × 16 covariance table. Right: the same table after the Fourier transform. Bottom: the diagonal, with the textbook spectrum as a line.
The covariance is r[k] = φ|k| (a first-order autoregressive signal, unit variance), for n = 16. The Fourier basis is the unitary DFT. The line is the textbook power spectrum (1 − φ²) / (1 − 2φ cos ω + φ²).
With no memory (φ = 0) the table is already the identity: white noise. With long memory, the spectrum piles up at low frequencies, and the Fourier table stays close to diagonal. Slow signals have mostly slow components.
Chapter 7
Test whether the Gaussian story fits your data in one two-dimensional picture, then ask why you needed the story at all
Your radar returns 40 numbers per echo. You fit two Gaussian clouds, one for birds and one for drones, and build the quadratic rule from Chapter 6. Before you trust it, you want a single glance that says: does this model separate the two classes, or not? With 40 axes you cannot look at the data directly. You need a picture that squeezes 40 dimensions into two.
The lecture’s trick uses the squared Mahalanobis distance from Chapter 4. For each echo x, compute how far it sits from the centre of class 1, in units of class 1’s own spread, and the same for class 2:
Plot each echo as the point (z1, z2). An echo from class 1 should be close to class 1 (small z1) and far from class 2 (large z2). An echo from class 2 does the reverse. The two classes land in two different corners, whatever the original number of dimensions.
There is a reason this works. For a true Gaussian class with n numbers per dot, z follows the chi-square law from Chapter 4: its mean is n and its typical wobble is √(2n). In 40 dimensions, that is a mean of 40 and a wobble of about 9. The cloud sits in a tight band.
The Gaussian rule is also a straight line in this picture. Classify as class 1 when z1 + ln|Σ1| < z2 + ln|Σ2|, assuming equal priors. That is z1 − z2 < ln|Σ2| − ln|Σ1|, a 45-degree line. So the plot shows both the data and the cut at once. If the classes sit on opposite sides of that line, the quadratic rule works. If the clouds overlap, it will not.
The lecture’s slide of a 40-dimensional radar signal shows two clouds, mostly apart, with the Bayes line between them. Let us break the plot on purpose. The usual cause is too few training dots (Chapter 0). The covariance estimate gets noisy, its inverse amplifies the noise, and every z becomes unreliable.
Each dot is a fresh test echo with 6 numbers. Both axes are logarithmic. The teal line is the Gaussian cut. Slide the number of training samples per class, and watch the two clouds slide into each other.
Illustrative: 6 numbers per dot; class 1 has covariance 0.6|i−j|, class 2 has a different shape with larger variance and centre shifted by 0.6 on every axis. Means, covariances and cut are estimated from the training samples you choose, then scored on 300 fresh dots per class. Even with unlimited data a few dots stay on the wrong side, since the clouds really overlap.
With 12 samples per class, the clouds blur into one another and roughly a quarter of the test dots land on the wrong side. With 400 samples, the plot opens up and the error falls to the true limit set by the overlap of the classes. The cure for the blur is more data, or a shrunk covariance (Chapter 0), or a lighter model.
Step back and look at what we did. To classify, we modelled the whole density of each class, p(x). We estimated means and covariances that describe where every dot lives. Then we derived the boundary as a by-product. LDA, QDA and the Bayes-optimal classifiers all work this way: they require modelling the signals p(x) and the class distributions p(y | x).
The lecture ends this part with a quotation from Vladimir Vapnik, as the slide gives it: when solving a problem of interest, do not solve a more general problem as an intermediate step. Our problem of interest is the boundary. Modelling the full density is a harder, more general problem, and as the picture above shows, it breaks when data is scarce.
Think of a border guard. To decide which side of the border you stand on, the guard does not need a map of both countries. She needs the line. This is the pivot of the lecture. From here on, we estimate the boundary directly, and we ask which boundary is the best one to draw.
Chapter 8
Measure how far a point sits from a flat cut, then ask for the cut whose closest point is as far as possible
You are laying a rope across a field to keep two herds apart. Dozens of ropes would do the job. Which one is best? A good answer is the rope that stays as far as possible from the nearest animal on either side. A sheep that wanders a step should not cross.
The rope is a hyperplane: the flat cut that splits a space in two. In two dimensions it is a line, in three a sheet, and in more dimensions it has no everyday name. The lecture writes its rule as wTx + b ≥ 0 with parameters θ = (w, b). Points where the score is positive are on one side. Points where it is negative are on the other.
H = { x : wTx + b = 0 }
The vector w is the normal: it points straight out of the cut, perpendicular to it. The number b slides the cut along w. The set H is exactly the points where the score is zero: the rope itself.
This is the key fact of the second half of the lecture, so we derive it slowly (slides 48 and 49). Take a point z. Walk from z straight to the cut, along the normal direction. Call the nearest cut point z0, and let r be the signed distance walked. Then
Divide by ||w|| and you have the distance.
d(z, H) = |r| = |wTz + b| / ||w||2
A worked case. Let w = (3, 4), so ||w|| = 5, and b = −10. The origin scores −10, so it sits 10/5 = 2 from the cut, on the negative side. The point (4, 3) scores 12 + 12 − 10 = 14, so it sits 14/5 = 2.8 away, on the positive side. Notice that multiplying both w and b by 7 gives scores 7 times larger and a norm 7 times larger. The distance does not change. Only the direction of w and the ratio b / ||w|| matter.
Drag the white point anywhere. Turn the line with the angle, or slide it with the offset. The dashed perpendicular is the shortest walk to the line.
The length of w is fixed at 2 so that the score is easy to check by eye. The point and the line are free. The formula in the read-out is the one derived above.
Now there are labelled dots x1 to xn with labels yi = +1 or −1. A hyperplane separates them when yi(wTxi + b) ≥ 0 for every i: each dot is on its own side. The margin of the hyperplane is the distance to the closest dot:
ρ(w, b) = mini d(xi, H) = mini |wTxi + b| / ||w||2
The margin is half the width of the empty street between the classes. The lecture’s plan: choose, among all separating hyperplanes, the one with the biggest margin.
maxw,b ρ(w, b) subject to yi(wTxi + b) ≥ 0 for all i
Why this one? Any wider street leaves less room for error. New dots from the same clouds land near the old ones, and a dot that strays a little still falls on the right side. The widest street is the most forgiving.
Try it on the lesson’s data. For each angle of the street, the best offset sits halfway between the closest red dot and the closest blue dot along that angle. That fixes the margin at that angle. Turn the angle and track the margin.
Top: the street at your angle, centred between the classes. Bottom: its margin at every angle. Find the angle where the curve peaks, or press the snap button.
The same toy points as the hero, without the stray one. For each angle the offset is centred between the closest red dot and the closest blue dot, so the margin is half the gap between them, measured along the normal. Angles where the classes do not separate show no street.
The curve has one clear peak, and at the peak the street is held by only a few dots, the ones touching its edges. The next chapter turns this picture into an optimization problem we can solve by computer.
Chapter 9
Fix the scale of w so the nearest dot scores exactly 1, and the widest street becomes the shortest w
The last chapter ended with a recipe: among all cuts that separate the classes, pick the one with the biggest margin. As written, the recipe has a max inside a min, and a trap hidden in the parameters. This chapter removes both, and ends with a clean problem a computer solves in a blink.
Slides 52 to 54 start from the recipe: maximize over (w, b) the smallest value of |wTxi + b| / ||w||, while every dot stays on its side.
Now notice that (αw, αb) describes the very same hyperplane for any α > 0. The cut has not moved, the distances have not changed, but the parameters are different. So there is no single best (w, b). There is a whole ray of equal answers. A solver would wander along that ray.
We are free to choose which member of the ray we want. Pick the one where the closest dot scores exactly 1. Divide w and b by m = mini |wTxi + b|. Now the closest dot has |wTx + b| = 1, and the margin becomes simple:
ρ = mini |wTxi + b| / ||w|| = 1 / ||w||2
The numerator is 1 by our choice, so only ||w|| is left. Play with the scale below. The line never moves, but the pair of lines wTx + b = ±1 slides in and out as you rescale. They touch the nearest dots at exactly one scale.
The green line is the hyperplane. The dashed lines are where wTx + b equals plus one and minus one. Slide the scale α and find where the dashed lines touch the nearest dots.
The fixed hyperplane is the widest street for the toy points, solved live. At α = 1 the pair (w, b) is the canonical one. The true margin never changes with α, only the number 1/||w||.
With the scale pinned, the closest dot scores 1 and every other dot scores at least 1. That turns the side-constraint into a clean inequality, and the goal into a single quantity to shrink:
This is the hard-margin support vector machine. The objective is a bowl (a quadratic), and the constraints are straight cuts (linear). That makes it a convex quadratic program: any local minimum is the global one, and the answer is unique. Solvers exist that are fast and reliable. The next lessons look inside one. See convex duality for the tool that solves it.
Take dots on a line: x = −1 with label −1, x = 3 with label +1, and x = 5 with label +1. The two nearest dots must score exactly −1 and +1: −w + b = −1 and 3w + b = 1. Subtract: 4w = 2, so w = 0.5 and b = −0.5.
The cut sits at x = 1, halfway between −1 and 3. The margin is 1/|w| = 2. Check the dot at 5: its score is 0.5 × 5 − 0.5 = 2, which is more than 1. That constraint has slack to spare. Delete the dot at 5, and the answer does not change. Only the dots at −1 and 3 matter.
Dots whose constraint holds with equality, yi(wTxi + b) = 1, are the support vectors. They sit on the edges of the street and hold it in place, like the poles that hold up a tent. Every other dot is a bystander.
Pink rings are support vectors. Push a dot that is not a support vector further away, and then push a support vector toward the street. Compare how w moves each time.
The street is solved live by a quadratic-program solver written for this page (the same problem, solved in its dual form). “Far dot” is the non-support dot farthest from the line; it moves 1.0 further from the street. A support vector moves 0.8 toward it.
This sparsity is the signature of the method. Fisher’s direction used every dot through the means and the covariances. The hard-margin line is built from a handful of them, and the rest could vanish without a trace.
Once you have w and b, a new dot x gets the label sign(wTx + b). The score wTx + b is also a confidence: scores beyond ±1 are outside the street. In code, with a library solver, this is clf = SVC(kernel="linear", C=1e6).fit(X, y) then clf.coef_ for w, clf.intercept_ for b and clf.support_ for the indices of the support vectors.
Chapter 10
Let a few dots slip into the street, pay a price for each, and let one dial C set how strict the price is
You have laid your rope with the widest gap you can. Then one stray sheep wanders into the other herd. If the rope must keep every animal on its side, you have two bad choices: the rope twists to a narrow, awkward line, or no rope works at all. A sensible farmer says: one sheep on the wrong side is cheaper than a rope that squeezes everything else.
The lecture names them on slides 56 and 57. The first is separability: if the classes overlap, so that no line has every dot on its own side, the constraints yi(wTxi + b) ≥ 1 cannot all hold, and the problem has no solution. Real signals overlap all the time, because sensors are noisy.
The second is sensitivity. Even when a separating line exists, one stray dot near the other class can drag the whole street. Chapter 9 said the line depends on its support vectors. A stray dot becomes a support vector, and it pulls the street with it. Drag the stray dot below and watch the street width.
Top: the hard-margin line for the stray blue dot at your position. Bottom: street width as the dot slides from far back (left) to inside the red cluster (right). Solid is hard margin; dashed is soft margin with C = 10.
Same toy data as the hero. The stray dot moves along a straight path from (−7.5, 3.6) to (1.9, 0.4). All widths are solved live. Hard margin stops where the classes first overlap and no line is left.
The solid curve is the symptom. It stays flat while the stray dot is far away, then falls fast as the dot nears the street, and finally stops. The dashed curve is the cure.
The cure on slide 58 gives every dot a slack variable si ≥ 0: how far dot i is allowed to fall short of the rule. The hard constraint becomes soft:
Read the slack as a distance in units of the street. If si = 0, the dot is on its own side and outside the street. If 0 < si < 1, the dot is on its own side but inside the street. If si = 1, it sits exactly on the cut. If si > 1, it is on the wrong side.
A worked case. Let w and b give a dot the score y f = 0.4. It needs at least 1, so it must carry slack s = 1 − 0.4 = 0.6. Another dot scores y f = −0.5. It needs s = 1 + 0.5 = 1.5. With n = 18 and C = 10, each unit of slack costs 10/18 = 0.56. The second dot adds 0.83 to the objective, and that price is paid to keep the street wide.
The problem is still convex: a bowl plus a linear cost, under linear constraints. The answer is unique, and solvers handle it as easily as the hard case.
C decides the trade. When C is large, slack is expensive, and the solution looks like the hard margin: a narrow street, almost no slips. As C goes to infinity, you recover the hard margin exactly. When C is small, slack is cheap. The street widens, and more dots slip inside it or across it. As C goes to zero, w shrinks toward zero and the street grows without bound.
The classes now overlap, so hard margin has no answer. Yellow rings show slack (bigger ring, more slack); red crosses are dots on the wrong side. The bars below compare the two parts of the objective.
Toy data we made up: the hero’s 16 dots plus one red dot just past the middle and one blue dot just past it on the other side, so n = 18. Each solution is computed live, with C/n as the price of one unit of slack.
Once w and b are fixed, the cheapest slack for dot i is si = max(0, 1 − yi(wTxi + b)). That function is the hinge loss: zero while the dot is safe beyond the street, then rising in a straight line. So the soft margin SVM minimizes ½||w||² + (C/n) Σ max(0, 1 − yif(xi)): a penalty on the size of w (like weight decay) plus an average loss over the data. This is the pattern of most machine learning, with a loss and a regularizer. Only the loss differs.
One limit remains. A straight cut still cannot separate rings or crossed ellipses, however well you tune C. The escape from Chapter 6, adding curved features, comes back as kernels.
Chapter 11
Review the whole lecture on one page: the numbers, the checklist, the core code, and where to go next
You can now rebuild Lecture 9 of EE269 from memory. It was given by Mert Pilanci on October 12, 2020 and runs from covariance recap to the soft-margin support vector machine. The lecture has two halves joined by one question. The first half models each class as a cloud and finds the best view of the clouds. The second half skips the clouds and draws the best boundary.
With few samples, covariance estimates are unstable, so we shrink them or count unknowns carefully. Fisher’s discriminant projects dots to a line, aTx, and maximizes the ratio of squared centre gap to combined spread, aTQa / aTPa. Whitening P turns the ratio into an eigenvalue problem, and the answer is a = P−1(μ1 − μ2). For K classes, the columns of A are the top eigenvectors of SW−1SB, at most K − 1 of them. A line fails on rings and crossed shapes, quadratic discriminants bend, and stationary signals make covariances diagonal in the Fourier basis. Vapnik’s principle says to estimate the boundary directly. The distance to a hyperplane is |wTz + b| / ||w||, the margin is the nearest dot’s distance, and pinning the scale gives the hard-margin SVM: minimize ||w||² with yi(wTxi + b) ≥ 1. Slack variables and the dial C give the soft-margin SVM.
| What | Number | Why it matters |
|---|---|---|
| LDA unknowns, n = 200, K = 5 | 1,000 + 20,100 = 21,100 | Far more than a few hundred dots can pin down |
| QDA unknowns, same case | 1,000 + 5 × 20,100 = 101,500 | Separate shapes cost K times as much |
| Fisher score, means (4, 2) and (0, 0), identity spread | 8 along x, 2 along y, 10 along the gap | Direction matters, length does not |
| Best direction, P = diag(4, 1), d = (4, 2) | a = (1, 2), J = 8 | P−1d beats the plain gap direction (5.88) |
| Three classes, SW = 30 I | λ = 2.67 and 2; J = 5.33 | J for m directions is the product of the top m eigenvalues |
| Chi-square percentiles, 2 dimensions | χ²2(0.1) = 4.61; χ²2(0.01) = 9.21 | Radius squared of the 90% and 99% ellipses |
| 90% ellipse, σ1 = 2, σ2 = 1 | area 29.0 (99%: 57.9) | Area = π χ² |Σ|1/2 |
| Stationary signal, 200 samples | about 200 numbers, not 20,100 | One value per lag, or per frequency |
| Distance, w = (3, 4), b = −10 | origin 2; (4, 3) is 2.8 | d = |wTz + b| / ||w|| |
| Hard margin, dots −1, 3, 5 | w = 0.5, b = −0.5, margin 2 | Only the dots at −1 and 3 hold the street |
| Soft margin price, C = 10, n = 18 | 0.56 per unit of slack | C/n sets how strict the street is |
Fisher for many classes, then a soft-margin SVM by gradient steps on the hinge loss. The first is exact, the second approximate. Real libraries solve the SVM as a quadratic program.
pythonimport numpy as np def fisher_directions(X, y, ridge=1e-6): # X: (N, n) dots, y: (N,) labels 0..K-1 mu = X.mean(0) Sw = np.zeros((X.shape[1],) * 2); Sb = np.zeros_like(Sw) for k in np.unique(y): Xk = X[y == k]; mk = Xk.mean(0) Sw += (Xk - mk).T @ (Xk - mk) # within-class scatter, (n, n) d = (mk - mu)[:, None] Sb += len(Xk) * d @ d.T # between-class scatter, (n, n) Sw += ridge * np.trace(Sw) / len(Sw) * np.eye(len(Sw)) # keep S_W invertible vals, vecs = np.linalg.eig(np.linalg.solve(Sw, Sb)) # eigenvectors of S_W^-1 S_B order = np.argsort(-vals.real)[: len(np.unique(y)) - 1] # at most K-1 are useful return vecs[:, order].real # A: (n, K-1); project with X @ A def soft_svm(X, y, C=10.0, lr=0.01, steps=5000): # y in {-1, +1} n, d = X.shape; w = np.zeros(d); b = 0.0 for _ in range(steps): viol = y * (X @ w + b) < 1 # dots with slack: inside the street or wrong gw = w - (C / n) * (y[viol, None] * X[viol]).sum(0) gb = -(C / n) * y[viol].sum() w -= lr * gw; b -= lr * gb # subgradient of 1/2|w|^2 + (C/n) sum hinge return w, b # predict with sign(X @ w + b)
Fisher’s method belongs with the other ways to reduce dimension, such as PCA, and with the Gaussian classifiers of Bayes classifiers. The cloud picture is the multivariate Gaussian. The earlier lectures set up what we used: distance-based classification, the DFT, stationary signals and Fisher’s discriminant itself. Next come convex duality, the tool that solves the SVM, and kernels, the answer to rings and crossed ellipses.
Now press Present or Teach and explain, from memory, why a ratio of two quadratic forms becomes an eigenvalue problem, and why only the support vectors move the SVM. Then go back to the stray point at the top and predict, before you drag it, which of the three lines will swing and which will stay still. Course credit: Mert Pilanci’s EE269, with the original Lecture 9 slides.