One picture: two overlapping clouds and a dividing line. LDA models each class’s cloud. A boundary decides the label; the cloud area on the wrong side tells us how often it makes mistakes.
Slides → small steps → practice. Browse the original slides at each topic, or click to enlarge. Keep the formula sheet nearby. Module 5 builds the classification and logistic-regression ideas used here.
1. LDA: which class could have produced this input?
Start with a story for making the data
Linear discriminant analysis (LDA) imagines two steps:
- Pick a class label . Its prior is how common that class is before seeing the input.
- Draw the input from that class’s bell-shaped, or Gaussian, distribution. Its density is .
Here is the input we observe; names a class. LDA uses a separate center for each class but a shared spread. With several inputs, it shares the whole covariance matrix: the spread and how inputs vary together.
Density is curve height; probability is area. For a continuous input, at one exact point. We use to compare how plausible values near are within each class. Areas under give probabilities.
Bayes’ rule reverses the story
We observe the input and want the class. The posterior is the updated class probability after seeing :
is the number of classes; runs through them. The numerator is class frequency × fit to this input. The denominator adds every class’s weight so the answers sum to 1.
Invented example: at one input, suppose priors are , and densities are , .
Using total weight , the posterior for class 1 is . Class 0 wins even though class 1’s density is taller: class 0 started much more common.
The classifier only needs the largest weight
With equal costs for mistakes, choose the most probable class:
is the classification rule; is its predicted label. Arg max means “return the class label with the biggest value.” The shared denominator cannot change which class wins.
This is Bayes optimal when the probabilities are correct: it minimizes the chance of a wrong label. Fitting LDA from data estimates those probabilities, so its quality depends on both the data and its Gaussian, shared-spread assumptions.
2. One input: turn bell curves into straight scores
Mean = center; standard deviation = spread
Univariate means one input. Write
The class center is . The second number, , is the variance; its square root is the standard deviation. LDA uses the same positive variance for all classes.
The Gaussian density is
Here is the mathematical constant; with a subscript is a class prior. Exp means .
Compare a simpler score
Taking logs preserves the ordering of positive weights. After dropping terms shared by all classes, the discriminant score is
is the natural logarithm. Choose the class with the largest . The score is a line in : this is where “linear” comes from. The score itself is not a probability.
Slide example: , , shared , equal priors . The squared-mean penalty is the same for both classes: . To find the boundary, set the two scores equal:
Both constants cancel, leaving , so . To the right, class 2’s score is larger.
Equal priors put the boundary halfway between the means
For classes 0 and 1 with , define input boundary :
Predict 1 when , and 0 otherwise. For equal priors, , so only the midpoint remains. Increasing class 1’s prior moves the boundary left: it takes less input evidence to choose that class.
Why does the squared input disappear?
Start with the log of the weighted density:
Expand the square. The pieces and are identical for every class. Removing them leaves . Shared variance is what makes that cancellation possible.
3. Learn the clouds from data
Usually the centers, spread, and priors are unknown. A hat means estimated from the training data. Let count all training observations, count classes, and count observations whose true label is .
Count each class; average within each class
is observation ‘s input and is its true label. The sum includes only observations in class .
Pool the leftover spread
Measure each input from its own class mean, square the differences, then combine them:
The denominator is because we estimated separate means. This is the shared pooled variance. If class sample variances are supplied instead:
Invented training data: class 0 has inputs ; class 1 has inputs . Thus , , and each .
- Priors: use : both are .
- Centers: use each group’s mean: and .
- Spread: each class’s deviations from its own mean are . Their squared sum is ; hence .
- Boundary: equal priors give midpoint .
Several inputs: the same comparison in more directions
Multivariate means several inputs. The input and class center are lists of numbers, called vectors. A shared covariance matrix records each input’s variance and which inputs tend to move together.
The clouds become ellipses in two dimensions. LDA still compares prior × density. Its boundaries become straight lines in two dimensions and flat separating surfaces in more dimensions.
For the multivariate Gaussian, write the adjusted squared distance as
Then its density is
is the offset from the class center. turns a column into a row; adjusts distance for spread and correlation; is the determinant, which scales the cloud’s volume. Use a nonsingular shared covariance matrix. With , , recovering the one-input formula.
4. Name a mistake before calculating its rate
Let positive = class 1, negative = class 0. “Positive” says what the model predicted; “true” or “false” says whether that prediction was correct.
| Outcome | Actual label | Predicted label |
|---|---|---|
| True positive (TP) | 1 | 1 |
| False positive (FP) | 0 | 1 |
| True negative (TN) | 0 | 0 |
| False negative (FN) | 1 | 0 |
Here TP, FP, TN, and FN stand for counts. With evaluated observations:
Invented counts: 4 false alarms and 6 missed positives among 100 observations give error.
Read the slide's counting notation as on/off switches
An indicator is 1 when statement is true and 0 otherwise. For true label and prediction :
Multiplying the switches counts a row only when both conditions hold. The slide’s is an equality switch: 1 when , otherwise 0. It plays the same counting role here; it is not a Gaussian density or the LDA score .
5. Confusion matrix: always ask “out of which group?”
A confusion matrix sorts the four counts into a table. The slides put predictions in rows, actual labels in columns. Other tables may swap them: read the labels first.
The supplied Default example evaluates the fitted classifier on its training data and calls default class 1:
| Prediction | Actual 0 | Actual 1 |
|---|---|---|
| Predict 0 | TN = 9644 | FN = 252 |
| Predict 1 | FP = 23 | TP = 81 |
| Actual totals | 9667 | 333 |
Use the actual class as the denominator
FPR and TNR divide the actual negatives. FNR and TPR divide the actual positives. Each pair adds to 1:
For the slide’s counts:
- False positive rate: .
- False negative rate: .
- True positive rate: .
- Overall training error: .
The small overall training error hides a large miss rate for actual defaults. Most observations are class 0. Even the null classifier, which always predicts 0, makes only errors on these observations, while missing every default. New-data performance requires a separate test set.
FPR is not “out of everything predicted positive.” Its denominator is everything actually negative. Say that group aloud before dividing.
6. Gaussian errors are areas across the boundary
Shade the wrong side of each class’s curve
Suppose we predict 1 for and 0 for . Each class density has total area 1:
The integral sign means “add up the area.” The first expression shades class 0’s right tail; the second shades class 1’s left tail.
Standardize: how many standard deviations away?
For a normal class with mean and standard deviation :
Let be the area to the left of under a standard normal curve, whose mean is 0 and standard deviation is 1. With class means and shared :
Then .
Invented one-class calculation: if , , and , the boundary is standard deviations above the center. Its right-tail error is .
Whole-population errors need the priors too
Conditional rates answer “among this actual class.” To find a fraction of everyone, multiply by that class’s prior:
For observations drawn from that population, expected counts are
means the long-run average over repeated samples. Invented example: , , , , and . Expected FP is ; expected FN is . Total error is .
Adding would mix rates with different denominators. Weighting them gives the fraction of all observations that are wrong.
7. Move the threshold; trade false alarms for misses
Probability threshold and input boundary are different numbers
Let be the posterior for class 1. The probability threshold says how sure we must be before predicting 1:
Equal mistake costs give the usual . A lower predicts 1 more often: it catches more actual positives (TPR rises, FNR falls) while also flagging more actual negatives (FPR rises). Raising reverses that tradeoff. On finite data, rates can stay unchanged between score values.
For the one-input LDA model with , the corresponding input boundary is
This formula uses . is a probability; is measured in the input’s units. If missing a positive costs more, choose a lower probability threshold to put more emphasis on catching positives.
ROC: show every threshold on one graph
The receiver operating characteristic (ROC) curve plots FPR horizontally and TPR vertically as the threshold changes. Every point is a different tradeoff for the same scoring model.
- Near : predict almost nobody positive.
- Near : predict almost everybody positive.
- Toward : catch positives with few false alarms.
AUC means the area under that ROC curve. Higher AUC summarizes better separation across thresholds; it does not choose the operating threshold or the preferred balance of mistakes. A diagonal curve has AUC ; perfect separation has AUC .
Try the boundary on the actual practice distributions
Use the Q3 and Q7 presets below. Move the boundary right and watch both TPR and FPR fall. Change a prior and notice why the overall error uses a weighted sum even though the conditional curves still each have area 1.
8. Shared practice Q3: two Gaussians centered at −3 and +3
View the original practice sheet (includes solutions)
Given: labels , both priors , and
The shared variance is 1, so the standard deviation is . Rules: Bayes and joint densities, LDA boundary, and Gaussian tail errors.
1. Joint density = class density × class prior
Write for the joint density in continuous input and discrete label . The rule is .
Using means , variance 1, and prior :
For , the squared term is ; for , it is . Each joint curve has area , because each label occurs half the time. Their two areas add to 1.
2. Draw equal-width curves; split at the midpoint
The conditional densities and have centers and each has area 1. Equal priors and equal variance give boundary
At the two posteriors tie, so either label is valid. A single point has zero probability here. The widget’s Q3 preset draws both curves and the boundary.
3. Find the negative class’s right-tail area
Standardize using boundary , negative-class mean , and standard deviation :
The 99.7% empirical rule puts approximately 0.997 of a normal curve within three standard deviations. The remaining mass splits equally between the two tails:
This is the practice approximation: 0.15% of actual negatives cross the boundary. An exact normal calculation gives , or . The difference is the empirical rule’s rounding.
The answer is a conditional tail area. Multiplying by the negative prior would instead give the fraction of the entire population that is a false positive.
9. Shared practice Q4: spam is the positive class
Given: a spam detector. Define as actually spam and as marked spam. Rule: confusion matrix rates.
| Rate | Plain-English question | Formula |
|---|---|---|
| FPR | Of actual nonspam emails, what fraction got marked spam? | |
| FNR | Of actual spam emails, what fraction slipped through as nonspam? | |
| TPR | Of actual spam emails, what fraction got caught? |
Memory aid: “false” means wrong; “positive” means the predicted spam label. FPR is a false alarm among legitimate emails. FNR is a miss among spam emails. TPR and FNR divide the same actual-spam group, so .
10. Shared practice Q7: decode a noisy 0 or 1
View Q7 on the original practice sheet (includes solutions)
Given: the transmitted bit is , each bit occurs half the time, and the received input is
Treat the channel noise as having this same distribution for either transmitted bit. Its mean is and its variance is , so its standard deviation is .
Rules: shifted Gaussian inputs, LDA boundary, Gaussian tails, and weighted error.
1. Substitute each possible bit
Adding a constant moves a distribution’s mean without changing its variance.
- If , then : mean , variance .
- If , then : mean , variance .
Thus
The supplied 50/50 transmission frequencies give both priors:
For , the mean is . Substitute this mean and into the normal density. The front factor becomes ; the exponent’s multiplier becomes . Thus
In particular,
These are densities; their areas, rather than individual heights, give probabilities.
2. Use the midpoint because priors and variances match
The LDA rule chooses the larger . With equal priors , equal variance , and means , the boundary is
3. Compute FPR, then use symmetry for TPR
FPR is among actual zeros. The mean is , standard deviation , and boundary :
Using the practice approximation that 95.4% lies within two standard deviations, the right tail is
FNR is among actual ones. This class has mean , standard deviation , and boundary :
The equal-width mirrored curve has left-tail mass . Therefore
So approximately 2.3% of actual zeros trigger a false 1, while 97.7% of actual ones are correctly received as 1. Exact normal values are and .
4. Weight the two kinds of error by how often each bit occurs
Use the total-error rule, the supplied priors , and calculated rates :
Invented batch-size illustration: for 1000 transmitted bits, expect 500 actual zeros and 500 actual ones. Expected false positives are and expected false negatives are also 11.5. Thus approximately 23 of the 1000 bits are wrong. Expected counts can be fractional; any one real batch has whole-number counts.
The exact Gaussian total error is about . The practice’s uses its two-standard-deviation approximation consistently.
11. Pick the calculation that matches the question
| Asked for… | First move |
|---|---|
| Class probability after observing | Prior × density, then normalize across classes. |
| Predicted label | Compare or LDA scores . |
| One-input boundary | Set the two scores equal; equal priors give a midpoint. |
| False positive or negative rate | Pick the actual class, then shade its wrong-side area. |
| Overall error | Weight each conditional error rate by its class prior. |
| A different error tradeoff | Move the probability threshold and read the ROC point. |
The shared sheet’s Q1, Q2, Q5, and Q6 are in Module 5. Reuse the Module 6 formula sheet when the numbers change.