SVM, Naive Bayes & Probabilistic Models
Level: 4 (Application — novel problems, no hints) Time limit: 60 minutes Total marks: 50
Question 1 — SVM Maximum Margin from Data (12 marks)
You are given four linearly separable 2-D training points:
- Positive class (): ,
- Negative class (): ,
(a) By inspection/symmetry, argue which points are the support vectors, and find the maximum-margin separating hyperplane using the constraint that support vectors satisfy . Assume by symmetry. (6)
(b) Compute the geometric margin . (3)
(c) Classify the new point and report the value of the decision function . (3)
Question 2 — Soft Margin, C and Kernel Choice (10 marks)
A colleague trains an RBF-kernel SVM on a noisy dataset and reports 100% training accuracy but only 62% test accuracy.
(a) Explain in terms of and what is most likely happening, and state precisely how you would change each hyperparameter to fix it. (5)
(b) For a soft-margin SVM, write the primal objective and explain the role of the slack variables and the penalty . What happens to the margin and number of support vectors as ? (5)
Question 3 — Gaussian Naive Bayes Prediction (12 marks)
A Gaussian NB classifier is trained to detect spam using one feature = "number of links in email". The fitted per-class statistics are:
| Class | Prior | Mean | Variance |
|---|---|---|---|
| Spam () | 0.4 | 6 | 4 |
| Ham () | 0.6 | 2 | 1 |
A new email has links.
(a) Compute the class-conditional likelihoods and using the Gaussian density. Leave answers to 4 significant figures. (6)
(b) Compute the posterior probability and give the predicted class. (4)
(c) GNB assumes feature independence given the class. If you added a second highly-correlated feature "number of images", would this assumption be violated, and what practical effect does the violation typically have on the classifier decision vs the probability estimates? (2)
Question 4 — Multinomial NB Text Classification with Laplace Smoothing (12 marks)
Training corpus (vocabulary = {win, free, money, meeting, report}):
Spam documents (2 docs):
- D1: "win free money"
- D2: "free money money"
Ham documents (2 docs):
- D3: "meeting report"
- D4: "report meeting report"
(a) Using Multinomial NB with Laplace (add-1) smoothing, compute the smoothed probability and . Use vocabulary size . (6)
(b) A new message is "free money". Using equal class priors , determine the predicted class by comparing the (unnormalized) log-scores. Show the smoothed probabilities used. (6)
Question 5 — Kernel Trick & Bernoulli NB Concepts (4 marks)
(a) State why the kernel trick lets an SVM find nonlinear boundaries without explicitly computing high-dimensional feature vectors, using the RBF kernel as your example. (2)
(b) How does Bernoulli NB differ from Multinomial NB in how it treats word occurrence in a document? (2)
Answer keyMark scheme & solutions
Question 1 (12 marks)
(a) By symmetry the closest opposing points are (positive) and (negative) — these are the support vectors (2). Let .
Support vector constraints ():
- For , :
- For , :
Subtract: ... solve directly: From and : subtract (2). Then (1).
Hyperplane: , i.e. (1).
(b) (1). Margin (2).
(c) ... check: . Actually so lies on the boundary; (2). Point is on the decision surface — ambiguous / margin boundary (1).
Question 2 (10 marks)
(a) Symptom = overfitting (1). Likely too large (hard penalty, fits noise) and/or too large (very peaked RBF, each point its own island) (2). Fix: decrease (allow more slack / wider margin) and decrease (smoother, wider kernel influence) (2). Use cross-validation grid search.
(b) Primal: (2). measures margin violation (how far point is inside margin / misclassified) (1). trades margin width against violations (1). As penalty vanishes → margin becomes very wide, many points become SVs, model tolerates more misclassification (underfits) (1).
Question 3 (12 marks)
Gaussian density .
(a) Spam: , : (3).
Ham: , : (3).
(b) Joint scores:
Evidence . (3). Predict Spam (marginally) (1).
(c) Yes — correlated features violate conditional independence (1). Effect: probability estimates become over-confident (poorly calibrated), but the classification decision (argmax) is often still accurate (1).
Question 4 (12 marks)
Spam word counts: win 1, free 2, money 3, meeting 0, report 0. Total Spam tokens . Ham word counts: win 0, free 0, money 0, meeting 2, report 3. Total Ham tokens . .
(a) Laplace: . (3). (3).
(b) Needed smoothed probs:
- ;
- ;
Score (with equal priors, drop the ):
- Spam:
- Ham:
Log-scores: vs (3). Spam score higher → predict Spam (3).
Question 5 (4 marks)
(a) The SVM dual depends only on inner products . A kernel replaces these with , computing the dot product in the (possibly infinite-dimensional, for RBF) feature space directly — no explicit needed (2).
(b) Bernoulli NB uses binary presence/absence of each vocabulary word (and penalizes non-occurrence), while Multinomial NB uses word counts/frequencies (2).
[
{"claim":"Q1 hyperplane a=1/3, b=-5/3","code":"a,b=symbols('a b'); sol=solve([2*a+b+1, 8*a+b-1],[a,b]); result=(sol[a]==Rational(1,3) and sol[b]==Rational(-5,3))"},
{"claim":"Q1 margin = 3*sqrt(2)","code":"w=sqrt((Rational(1,3))**2+(Rational(1,3))**2); m=2/w; result=simplify(m-3*sqrt(2))==0"},
{"claim":"Q3 posterior P(S|4) approx 0.599","code":"import math; pS=0.4*(1/math.sqrt(8*math.pi))*math.exp(-0.5); pH=0.6*(1/math.sqrt(2*math.pi))*math.exp(-2); post=pS/(pS+pH); result=abs(post-0.599)<0.01"},
{"claim":"Q4 Spam score > Ham score for 'free money'","code":"spam=(Rational(3,11))*(Rational(4,11)); ham=Rational(1,10)*Rational(1,10); result=spam>ham"},
{"claim":"Q4 P(money|S)=4/11","code":"result=Rational(3+1,6+5)==Rational(4,11)"}
]