PRP Part2 StudyNotes
PRP Part2 StudyNotes
Weeks 4–7 | Bayesian Decision Theory · Discriminant Functions · Naive Bayes · Evaluation Metrics
Wee
k4 Bayesian Decision Theory & Risk
Wee
k5 Discriminant Functions & Parameter Estimation
Wee
k6 Naive Bayes Classification
Wee
k7 Performance Evaluation & Metrics
Table of Contents 2
1. Bayesian Decision Theory & Risk 4
1.1 Key Terms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .4
1.2 Bayes Theorem (The Foundation) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
1.3 The MAP Decision Rule . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
1.4 Beyond MAP — Cost & Risk . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
1.5 The Loss Function λ(ω_i | ω_j) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
1.6 The Risk (Expected Loss) R(ω_i | x) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
1.7 Zero-One Loss — The MAP Connection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
1.8 Solved Example — Risk Calculation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
2. Discriminant Functions & Parameter Estimation 7
2.1 Key Terms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7
2.2 The Discriminant Function g_i(x) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
2.3 Decision Surfaces . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
2.4 Parameter Estimation — MLE vs MAP . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
2.5 Solved Example — Discriminant Function Decision . . . . . . . . . . . . . . . . . . . . . . . . 8
3. Naive Bayes Classification 10
3.1 Key Terms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
3.2 The Curse of Dimensionality Problem . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
3.3 The Naive Assumption — The Solution . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
3.4 The Naive Bayes Decision Rule . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
3.5 Why 'Naive' Still Works . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
3.6 Application: Spam Filter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
3.7 Solved Example — Naive Bayes Spam Classification . . . . . . . . . . . . . . . . . . . . . . 11
4. Performance Evaluation & Metrics 13
4.1 Key Terms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
4.2 The Confusion Matrix . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
4.3 Key Performance Metrics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
4.4 Precision vs Recall — The Fundamental Trade-off . . . . . . . . . . . . . . . . . . . . . . . . 14
4.5 Why F1-Score? The Imbalanced Data Problem . . . . . . . . . . . . . . . . . . . . . . . . . . 14
4.6 Solved Example — Full Metrics Calculation . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
5. Full Topic Connections & Big Picture 16
5.1 The Decision Rule Hierarchy . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
5.2 Master Formula Reference . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
5.3 All Memory Lines . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
6. Exam-Style Practice Questions & Answers 18
6.1 Section A — Conceptual (MCQ) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
Prior P(ω_i) How likely class ω_i is BEFORE seeing any data. Your initial belief.
Likelihood P(x|ω_i) Probability of seeing data x IF the true class is ω_i. The class model.
Evidence P(x) Overall probability of seeing x. Same for all classes — acts as a normalizer.
Posterior P(ω_i|x) Updated belief: probability of class ω_i AFTER seeing data x. This is what we
maximize.
Loss λ(ω_i|ω_j) Penalty/cost when we decide class ω_i but true class is ω_j.
Risk R(ω_i|x) Expected (average) loss when we assign input x to class ω_i.
MAP Rule Choose class with highest posterior — most common decision rule.
Zero-One Loss All errors cost 1, all correct = 0. Makes MAP the optimal rule.
BDT General Rule Choose class that MINIMIZES expected risk. MAP is a special case.
Think of it like a courtroom: Prior = your initial hunch about guilt. Likelihood = how well the evidence fits that
hypothesis. Posterior = updated verdict after seeing the evidence. Evidence just ensures probabilities sum to
1 — ignore it when comparing classes!
Since P(x) is same for all classes, we only compare the numerator:
Why drop P(x)? We are comparing classes for the SAME input x. Since P(x) is identical for all classes,
dividing by it doesn't change which class wins. It's like asking 'who is taller?' — you don't need to know the unit
of measurement if you measure both in the same unit.
Medical Diagnosis Miss disease → patient untreated Healthy flagged → extra tests FN much worse!
Spam Filter Spam reaches inbox Legit email deleted! FP worse for user
Bomb Detection Miss actual bomb Evacuate for nothing FN catastrophically worse
Notation Meaning
λ(ω_1 | ω_2) = λ_12 Decided Class 1, but true class is Class 2 → Type I Error cost
λ(ω_2 | ω_1) = λ_21 Decided Class 2, but true class is Class 1 → Type II Error cost
Formula Intuition: 'If I call this class ω_i, what is the average damage I expect to cause?'
You loop over every possible true class ω_j. For each, you ask: (1) how much does it cost if I'm wrong in this
specific way? [loss] × (2) how likely is this true class? [posterior]. Sum all of these up = total expected damage
= Risk.
Bayes Decision Rule (General): Choose class ω_i that MINIMIZES R(ω_i | x)
Therefore: MAP is just a special case of BDT when you use Zero-One Loss. The hierarchy is: BDT
General Rule → (with Zero-One Loss) → MAP Rule.
Problem:
A medical classifier has two classes: ω_1 = Sick, ω_2 = Healthy. For a new patient x, the posteriors are:
P(ω_1|x) = 0.3, P(ω_2|x) = 0.7. Loss matrix: λ(ω_1|ω_1) = 0, λ(ω_2|ω_1) = 10 (miss disease!), λ(ω_1|ω_2) = 1
(unnecessary alarm), λ(ω_2|ω_2) = 0. Which class should we pick?
Step 3: Decision
Note: MAP would have chosen ω_2 (Healthy) since P(ω_2|x)=0.7 > P(ω_1|x)=0.3! But the asymmetric cost of
missing a disease overrides the raw probability. This is exactly why BDT is more powerful than MAP.
The Loss Function here is directly linked to the metrics you learn in Week 7. High λ for FN → your system is
optimized for high Recall. High λ for FP → your system is optimized for high Precision. BDT is the theoretical
foundation; Precision/Recall are the practical measurement tools.
Discriminant Function g_i(x) A scoring function for each class. The class with the highest score wins.
Decision Surface The boundary in feature space where two discriminant functions are equal:
g_1(x) = g_2(x).
Hyperplane A flat decision surface (line in 2D, plane in 3D). Result of a LINEAR
discriminant function.
MLE Maximum Likelihood Estimation: finds parameters θ that make observed data
most probable.
MAP Estimation Incorporates a prior belief about θ. Balances data evidence with prior
knowledge.
Sample Mean MLE estimate of µ: just the average of all training points for that class.
2 (Likelihood × Prior) P(x | ω_i) × P(ω_i) Drop P(x) — doesn't affect ranking.
3 (Log-Likelihood) ln[P(x|ω_i) × P(ω_i)] Preferred! Turns products into sums. Avoids numerical underflow.
WHY LOG?
Why use log? When features are independent (Naive Bayes), the likelihood is a product of many small
probabilities: P(x_1|ω)×P(x_2|ω)×...×P(x_D|ω). With many features, this product becomes astronomically
small (numerical underflow → rounds to 0). Taking log converts the product into a SUM: ln P(x_1|ω) + ln
P(x_2|ω) + ... + ln P(x_D|ω), which is numerically stable.
Quadratic in x Non-linear (ellipse, parabola, hyperbola) QDA, Gaussian with different covariances
θ_MLE = argmax_θ P(Data | θ) → For Gaussian: µ_MLE = (1/n) Σ x_i [sample mean]
With lots of data Very accurate Prior effect shrinks — approaches MLE
Analogy Just trust the data Trust data + your prior experience
Memory Line: 'MLE = trust the data fully. MAP = data + your prior wisdom. When data is
scarce, wisdom matters more.'
Problem: Two 1D Gaussian classes. Both have equal prior P(ω_1)=P(ω_2)=0.5 and equal variance σ²=1.
Means: µ_1=1, µ_2=4. Classify x=2.5 using the log-discriminant function.
Step 1: Log-discriminant for Gaussian (equal prior, equal σ²) simplifies to:
Since priors are equal, they cancel. We just compare -(x - µ_i)²:
Result: g_1 = g_2 → x=2.5 is exactly on the decision boundary! (Makes sense: midpoint of µ_1=1 and
µ_2=4 is 2.5.)
Topic Connections:
• Week 4 → Week 5: BDT tells us to maximize posterior. Discriminant functions ARE the posterior (or a
monotone transform of it) — they're the computational tool to apply BDT.
• Week 5 → Week 6: MLE is used inside Naive Bayes to estimate each P(x_j|ω_i).
• Week 5 → Linear Algebra: Equal covariance Gaussians → hyperplane boundary. Different covariances →
quadratic (curved) boundary.
Curse of Dimensionality As number of features D grows, the data needed to estimate the joint
distribution grows exponentially.
Joint Likelihood P(x_1, x_2, ..., x_D | ω_i) — the full probability of observing all features
together, given a class.
Conditional Independence Features x_1...x_D are assumed independent GIVEN the class. Key: 'given
the class' is crucial.
Naive Assumption The 'naive' simplification: treat features as conditionally independent given
the class.
Individual Likelihood P(x_j | ω_i) — probability of a single feature value given the class.
Bernoulli NB For binary features (0/1). Used when features represent presence/absence.
Multinomial NB For count features (word frequencies in text). Classic spam filter model.
Laplace Smoothing Add-1 trick: add 1 to all counts to avoid P(word|class) = 0 for unseen words.
D=10 features, k=10 values each → 10^10 = 10 BILLION combinations per class!
P(x_1, x_2, ..., x_D | ω_i) ≈ P(x_1|ω_i) × P(x_2|ω_i) × ... × P(x_D|ω_i) = Π_j P(x_j|ω_i)
What this saves: Instead of estimating 1 joint distribution over D features, you estimate D separate 1D
distributions. For D=10, k=10: instead of 10^10 parameters, you only need D×k = 10×10 = 100 parameters.
Reduction factor: 10^8 (100 million times fewer!).
Start with your prior (log P(ω_i)) — this is your 'base score'. Then for each feature, add the evidence it
provides (ln P(x_j|ω_i)). Positive features strengthen the score, negative features weaken it. The class with the
best total score wins. It's like a courtroom where each witness adds their vote.
Even if our probability estimates are wrong, the RANKING of classes (which posterior is highest) is often
preserved. As long as Class A gets a higher score than Class B, the decision is correct — even if the exact
numbers are off. Naive Bayes gets the ordering right surprisingly often.
Likelihood P(x_j|ω) How often word j appears in Spam/Ham emails P('discount'|Spam)=0.8, P('discount'|Ham)=0.02
Memory Line: 'Naive Bayes = Split the courtroom evidence. Each witness (feature) speaks
independently. Sum up all votes. Most votes wins. Unrealistic? Yes. Effective? Surprisingly
yes.'
Note: Even though 'meeting' is a Ham word, the strong spam signal from 'free' and 'discount' dominates.
Topic Connections:
• Week 4 → Week 6: Naive Bayes is just MAP rule with the independence assumption. Same posterior
maximization, simpler likelihood.
• Week 5 → Week 6: MLE is used to estimate each P(x_j|ω_i) from training data.
• Week 6 → Week 7: After building the Naive Bayes model, you evaluate it using Confusion Matrix, Precision,
Recall, F1.
Confusion Matrix A 2×2 table showing all four possible outcomes: TP, TN, FP, FN.
False Positive (FP) Model predicted Positive. Actual is Negative. Wrong! = Type I Error = False
Alarm.
False Negative (FN) Model predicted Negative. Actual is Positive. Wrong! = Type II Error = Miss.
Precision TP/(TP+FP) — of all predicted positives, how many are real? 'Quality of
positives.'
Recall (Sensitivity) TP/(TP+FN) — of all real positives, how many did we catch? 'Coverage of
positives.'
F1-Score Harmonic mean of Precision and Recall. Best single metric for imbalanced
data.
Imbalanced Dataset When one class has far more samples than the other. Accuracy becomes
meaningless.
Memory Line: 'True = model was RIGHT. False = model was WRONG. Positive/Negative = what
the model PREDICTED.'
Accuracy TP+TN / Total Overall, how often is the model Balanced datasets only
correct?
Recall TP / (TP+FN) Of all actual positives, how many When FN is costly (disease
(Sensitivity) did the model find? detection)
Specificity TN / (TN+FP) Of all actual negatives, how many When TN matters too
were correctly rejected?
Minimize false alarms HIGH Precision Accept more FN (miss some positives)
Spam filter: don't delete real emails
Catch everything real HIGH Recall Accept more FP (more false alarms)Cancer test: catch every sick patient
Balance both HIGH F1-Score Best harmonic mean of P and R General classification
Why Harmonic Mean (not Arithmetic Mean)? Arithmetic mean: (1.0 + 0.0) / 2 = 0.50 — makes a model with
100% Precision but 0% Recall look 'decent'. Harmonic mean: 2×(1.0×0.0)/(1.0+0.0) = 0.0 — correctly
penalizes this model to 0. Harmonic mean is dominated by the SMALLER value — it forces both P and R to be
high.
Problem: A classifier is tested on 1000 samples. Results: TP=100, FP=10, FN=5, TN=885. Calculate all
metrics and comment on model performance.
Interpretation: The model is excellent! High Recall (95.2%) means it catches most actual positives. High
Precision (90.9%) means most of its positive predictions are correct. Only 5 positive cases were missed
(FN=5) and only 10 were false alarms (FP=10).
• Week 4 BDT → Week 7: Minimizing FN cost (high λ for FN) = maximizing Recall. Minimizing FP cost =
maximizing Precision.
• Week 6 Naive Bayes → Week 7: After training NB on spam, you evaluate with Precision/Recall. High
Precision spam filter = fewer good emails lost.
• Validation Set: NEVER tune hyperparameters on test set — this causes data leakage. Use separate
train/val/test splits.
Special Case 1 (Equal costs) MAP Rule: Maximize Posterior P(ω_i|x). Equivalent to Zero-One Loss.
Special Case 2 (No prior) MLE Classification: Maximize Likelihood P(x|ω_i) only. Equal priors assumed.
Practical NB Version Naive Bayes: MAP + Conditional Independence. Scales to high dimensions.
Precision TP / (TP+FP)
Recall TP / (TP+FN)
W5: 'MLE = trust the data fully. MAP estimation = data + prior wisdom. Less data = trust prior
more.'
W6: 'Naive Bayes: each feature votes independently. Add up the votes. Most votes wins.'
W6: 'Naive? Yes. Effective? Surprisingly yes — ranking matters more than exact numbers.'
W7: 'Accuracy lies when classes are unequal. F1 always tells the truth.'
W7: 'TP/TN = correct. FP = false alarm. FN = missed! Type I=FP, Type II=FN.'
W7: 'Precision = quality (don't cry wolf). Recall = coverage (catch all wolves).'
Answer: B — Under Zero-One loss, minimizing R(ω_i|x) = Σ_{j≠i} P(ω_j|x) = 1-P(ω_i|x), which is minimized by
MAXIMIZING P(ω_i|x) — exactly the MAP rule.
Q2. A hospital needs to minimize deaths from undetected cancer. The cost of False Negative is
100x the cost of False Positive. What should the BDT-optimal classifier prioritize?
A. High Accuracy
B. High Precision
C. High Recall
D. High Specificity
Q3. Naive Bayes solves the Curse of Dimensionality. With D=20 features, each taking 3 discrete
values, how many parameters are saved per class by using Naive Bayes (vs full joint)?
A. 60 saved
B. 3^20 - 60 ≈ 3.5 billion saved
C. 20 saved
D. No parameters are saved
Answer: B — Full joint needs 3^20 ≈ 3.5 billion parameters. NB needs D×k = 20×3 = 60 parameters. Savings
≈ 3,486,784,341 parameters per class — essentially impossible to estimate without NB.
Q4. A classifier's discriminant function g_i(x) is linear in x. What shape is its decision boundary?
A. Ellipse
B. Parabola
C. Hyperplane (straight line/plane)
D. Circle
Q5. MLE estimates are obtained by maximizing P(Data|θ). When data is scarce, MAP estimation is
preferred. Why?
Answer: B — With few data points, MLE can overfit to noise. MAP adds a prior P(θ) that acts as regularization
— it biases the estimate toward expected values, reducing variance.
Solution:
Key: MAP missed the fraud (chose Legit) but BDT correctly flagged it due to high miss-cost!
Problem 2 — Metrics: A model is tested: TP=80, FP=20, FN=10, TN=890. Calculate Accuracy, Precision,
Recall, and F1-Score. Is this model better for precision-critical or recall-critical tasks?
Recall (88.9%) > Precision (80%) → better at recall-critical tasks (e.g., disease detection where catching all
positives matters more than avoiding false alarms).
Why log in discriminant Turns products into sums (numerically stable). Avoids floating-point underflow
with many features.
Naive in Naive Bayes Naive = conditional independence assumption. Features are assumed
independent GIVEN the class. Almost never true, but works.
MAP vs MLE estimation MLE: maximize P(Data|θ). MAP estimation: maximize P(θ|Data) =
P(Data|θ)×P(θ). MAP adds a prior on θ.
F1 vs Accuracy Use F1 when dataset is imbalanced. A lazy 'always predict majority' model gets
high accuracy but F1≈0.
Type I vs Type II Type I = False Positive (false alarm). Type II = False Negative (miss).
Remember: 'crying wolf' is Type I.
Hyperplane condition Decision boundary is a hyperplane ONLY when the discriminant function is
LINEAR in x.
When to use which metric Prioritize Precision: losing good emails (FP) is worse than letting some spam
for spam through (FN).
Validation set importance Never tune on test set! Causes data leakage. Test set must remain unseen
until final evaluation.