Bayes and joint densities
Weight each class by how common it is and how well it fits the input. Let name a class, be an observed continuous input, its prior, and the density of within that class. There are classes.
The joint density in and discrete label is
Its area over all is . A conditional density has area 1. Density is curve height; the probability of a continuous input interval is its area, and at an exact point.
The posterior, or class probability after seeing , is
runs through all class labels. For equal mistake costs, choose
is the predicted label; arg max returns the label with the largest weight. The denominator is the same for every candidate class.
Invented numbers: priors and densities give weights . Class 1’s posterior is ; predict class 0.
Q3: labels , means , shared variance 1, and priors give
Univariate LDA
Model one bell curve per class with a shared spread. For input and class :
is the class mean; is the common variance; is the standard deviation. Here is the mathematical constant and is the class prior. .
Instead of comparing weighted densities , compare linear discriminant scores:
is the natural logarithm. Predict the label with the largest score. A discriminant score is not itself a probability.
For classes 0 and 1 with , equal mistake costs give input boundary
Predict 1 for , otherwise 0. Equal priors give , hence the midpoint. If the means are reversed, reverse the direction of the threshold rule. If they coincide, identical densities leave only the priors to compare.
Q7: means , variance , and priors give . Q3: means and equal priors also give , using labels .
Estimating LDA from data
Count classes, average within classes, then pool the within-class spread. Let training pair contain input and true label . There are observations and classes; is class ‘s count. Hats mean estimates.
The shared estimated variance is
Each difference uses its own class’s mean. If the class sample variances are given, the equivalent rule is
where when . The denominator accounts for estimating one mean per class. The pooled-deviations rule needs each class represented, , and a positive result to use as an LDA variance.
Invented data: class 0 inputs ; class 1 inputs . Then , , each ; priors are . Means are and . Squared within-class deviations sum to , so pooled variance is .
Insert these estimates into the LDA score to classify new inputs.
Multivariate LDA
Several inputs make a cloud rather than a one-dimensional bell curve. Let contain input values, contain the class means, and be the shared nonsingular covariance matrix. Covariance records input spreads and how inputs move together.
Define the adjusted squared distance
Then the class density is
is the offset from the class center; denotes transpose; adjusts for spread and correlation; is the determinant; is the mathematical constant. With class priors , predict the class with largest .
For , and , giving the usual univariate normal density. Shared covariance gives linear class boundaries: lines for two inputs, flat surfaces in higher dimensions.
Confusion matrix rates
Name the actual class before choosing the denominator. Positive means class 1; negative means class 0. These symbols are counts:
| Prediction | Actual 0 | Actual 1 |
|---|---|---|
| Predict 0 | True negative (TN) | False negative (FN) |
| Predict 1 | False positive (FP) | True positive (TP) |
Among actual negatives:
Among actual positives:
The denominator must be nonzero. Overall, with :
Slide training counts: , , , . Hence , , , and training error . These describe the training data; test performance needs new observations.
Q4, spam is positive: FPR is legitimate email incorrectly marked spam, divided by all actual legitimate email. FNR is missed spam divided by all actual spam. TPR is caught spam divided by all actual spam.
Count mistakes with indicators
For observation , let be its true label and its predicted label. An indicator equals 1 if statement is true, otherwise 0:
Both switches must be on to count a row. The slides’ equality switch for , otherwise 0, serves the same purpose.
Gaussian tail errors
Standardize the boundary, then take the area on the wrong side. Suppose classes 0 and 1 have normal means , shared standard deviation , and the rule predicts 1 for .
The standard-normal cumulative distribution function gives the area to the left of for . The standardized boundary for class is
For class density , conditional error rates are
Then .
Each conditional density has total area 1. An integral adds curve area, giving probability.
Q3: use negative-class mean , , and boundary . Then . The 99.7% empirical rule gives one tail . Exact normal area is .
Q7: use means , , and boundary . Then and . The practice approximation gives
Exact Gaussian values are and . Use either exact values or the stated empirical approximation consistently.
Population error and expected counts
Conditional rates have different denominators; use priors to combine them. Let and be actual class frequencies, with . Let and , where is the predicted label.
For a batch of observations drawn from this population, denotes an expected count:
Q7: equal priors and the approximate rates give error . An invented batch of has expected FP and the same expected FN, or 23 expected mistakes total.
Expected counts can be fractional; observed counts cannot. For a dataset, using its observed class proportions and observed conditional rates recovers exactly.
Shifted Gaussian inputs
Adding a constant moves the center without changing the spread. Suppose
is a class label; is a supplied multiplier; is the noise mean and its variance. The same noise distribution is assumed in each class. Substituting gives
With , its density is
Q7 supplies , , , and . Thus means are and , with standard deviation in both classes:
Equal transmitted frequencies give . The Gaussian’s second parameter is variance, so do not use as the standard deviation.
Thresholds and ROC
The threshold chooses the balance of misses and false alarms. Let be the posterior for class 1 and a probability threshold:
Equal costs for false positives and false negatives give . Lowering can increase TPR and FPR while decreasing FNR; raising it reverses those changes. Counts may stay unchanged between observed scores.
For univariate LDA with class means , common variance , priors , and , the equivalent input boundary is
Predict 1 for . is a probability; has the input’s units. is the natural logarithm.
Q7 model, invented threshold: means , variance , equal priors, and give
Moving left from the usual boundary 0 predicts more positives, catching more actual ones and also more actual zeros.
An ROC curve plots horizontally and vertically while varying the threshold. Here FPR is the fraction of actual negatives flagged positive; TPR is the fraction of actual positives caught. Each point is one threshold. The desirable corner is .
AUC is the area under the ROC curve: 1 for perfect separation and 0.5 for a diagonal curve. It summarizes separation across thresholds; costs and acceptable error rates still determine which threshold to use.