Linear discriminant analysis: classify parts or lots, example
Discriminant analysis uses measurements on observations whose group you already know, such as good and bad lots, to build a rule that assigns new observations to a group. Linear discriminant analysis (LDA) assumes each group is spread like a multivariate normal distribution with the same covariance matrix, and gives one linear function per group; a new observation goes to the group whose function scores highest. It also shows which measurements separate the groups and how well.
When to use it
- You know from experience which past lots ran well and which caused trouble, and you have incoming test results for all of them.
- You want a rule to screen new lots, parts or batches before they reach production.
- You want to know which combination of measurements best separates two or more groups.
- You have a few numeric predictors and groups of similar spread; with many predictors or very different spreads, consider logistic regression or quadratic discriminant analysis.
How it works
For each group g, compute the mean vector x̄_g. Pool the within-group covariance matrices into one matrix S, weighting each by its degrees of freedom. The linear discriminant function for group g is:
f_g(x) = x̄_gᵀ S⁻¹ x − ½ x̄_gᵀ S⁻¹ x̄_g (+ ln p_g with prior p_g)A new observation x goes to the group with the largest f_g(x). With equal prior probabilities, as here, the ln p_g term is the same for all groups and drops out. This is the same as choosing the group whose mean is closest in Mahalanobis distance, a distance that accounts for the spread and correlation of the measurements:
D²_g(x) = (x − x̄_g)ᵀ S⁻¹ (x − x̄_g)Posterior probabilities follow from these distances: with two groups and equal priors, P(g | x) = exp(−D²_g/2) / Σ exp(−D²_h/2).
To judge the rule, classify the data it was built from. That resubstitution rate is optimistic, because each observation helped build the rule. Leave-one-out cross-validation removes each observation in turn, rebuilds the rule from the rest and classifies the removed one, which gives a more honest error rate.
Example
A molding plant suspects that some resin lots cause short shots (incompletely filled parts). From the last 20 lots, it has the incoming melt flow index (MFI, g/10 min) and moisture (ppm), and it knows which 10 lots ran well and which 10 caused short shots.
| Good: MFI | Moisture | Short shots: MFI | Moisture |
|---|---|---|---|
| 13.1 | 650 | 11.3 | 820 |
| 11.6 | 650 | 12.2 | 1010 |
| 12.8 | 740 | 10.2 | 410 |
| 12.9 | 520 | 11.2 | 790 |
| 12.7 | 650 | 11.7 | 850 |
| 12.9 | 600 | 10.7 | 1140 |
| 12.4 | 490 | 12.9 | 760 |
| 12.9 | 530 | 12.0 | 920 |
| 12.3 | 610 | 10.3 | 740 |
| 12.3 | 480 | 11.6 | 850 |
The group means are 12.59 g/10 min and 592 ppm for good lots, 11.41 g/10 min and 829 ppm for short-shot lots. The pooled within-group standard deviations are 0.68 g/10 min and 148 ppm, with a correlation of 0.28.
The linear discriminant functions, with equal priors:
f_good = −171.53 + 27.680 · MFI − 0.00918 · Moisture
f_short = −140.58 + 24.187 · MFI + 0.00626 · MoistureTheir difference, d = f_good − f_short = −30.95 + 3.493 · MFI − 0.01544 · Moisture, is positive for lots that look good. Higher flow and lower moisture both push a lot toward the good group. The distributions of d in the two groups:
How well does it classify?
| Method | Correct | Rate |
|---|---|---|
| Resubstitution | 18 of 20 | 90% |
| Leave-one-out cross-validation | 17 of 20 | 85% |
Resubstitution misclassifies one good lot (11.6, 650), whose flow is low, and one short-shot lot (12.9, 760), whose flow is high. Cross-validation also loses the short-shot lot with very low moisture (10.2, 410). Expect about 85% accuracy on new lots, not 90%.
A new lot arrives with MFI 12.0 and moisture 700 ppm. Its scores are f_good = −171.53 + 27.680 × 12.0 − 0.00918 × 700 = 154.21 and f_short = 154.04. It is classified as good, but barely: the posterior probability of good is 0.54. The plant decides to dry this lot longer before use rather than trust a coin flip.
How to read the results
- Use the cross-validated error rate. It is the honest estimate of how the rule will do on new lots.
- Look at the posterior probabilities, not just the class. A lot at 0.54 and a lot at 0.99 get the same label but deserve different actions.
- Read the coefficients of the difference function with care. They depend on the units; standardized coefficients compare the variables fairly.
- Check which groups are confused. With three or more groups, the classification table shows which pairs are hard to separate.
Common mistakes
- Reporting only resubstitution accuracy. It flatters the rule, more so with few observations and many variables.
- Ignoring unequal group sizes or costs. If short shots are rare, or far more costly than an extra drying step, set the priors or the decision threshold to reflect that.
- Assuming equal covariances blindly. If one group is much more spread out, quadratic discriminant analysis or logistic regression may classify better.
- Using it to find groups. LDA needs known groups. To discover groups, use cluster analysis.
Frequently asked questions
What is the difference between discriminant analysis and logistic regression?
Both classify into groups. LDA assumes normal predictors with equal covariances and is efficient when that holds. Logistic regression models the probability of the group directly, makes fewer assumptions about the predictors and handles categorical predictors easily.
What does the prior probability do?
It shifts the boundary toward the rarer group. If only 10% of lots cause short shots, using priors of 0.9 and 0.1 makes the rule call a lot "short shot" only when the evidence is stronger.
Can LDA handle more than two groups?
Yes. Each group gets its own function, and an observation goes to the group with the highest score. With k groups there are up to k − 1 canonical discriminant directions, which you can plot to see the separation.
How many observations do I need?
Several times more observations per group than predictors. With 10 lots per group and two predictors, as here, the rule works but its coefficients are rough; collect more lots before relying on it.