MACHINE LEARNING/Student Engineering Notebook
Page 04·notes
LOGISTIC REGRESSION, K-NN, NAIVE BAYES & LDA—~28 MIN READ

k-Nearest Neighbors & Naive Bayes with Laplace Smoothing

“Voronoi decision cells, non-parametric boundary complexity, conditional independence, and add-1 smoothing.”

1.Instance-Based vs Generative Classifiers

k-Nearest Neighbors (k-NN): A non-parametric, lazy-learning algorithm that makes predictions based on the majority label among the k closest training points.

The Bias-Variance Knobs of k-NN:

- Small k (e.g. k=1): Complex, highly flexible decision boundary. High variance, zero training error, sensitive to outliers.

- Large k (e.g. k=N): Oversmoothed decision boundary predicting the global majority class. High bias.

Naive Bayes: A generative probabilistic classifier that assumes all features are conditionally independent given the class label. While the conditional independence assumption is rarely true in reality, Naive Bayes performs surprisingly well for high-dimensional text classification.

WORKED EXAM ANALYSIS · STEP-BY-STEP DERIVATION

2. Worked Practice Problem: Laplace Smoothing Calculation

⚠️ Pitfall Warning:

Do not forget to smooth both positive and negative conditional frequencies when estimating probabilities from sparse data.

Problem: In a binary text classification training set of 20 documents (12 Spam, 8 Ham), the word 'prize' appears in 6 Spam documents and 0 Ham documents. If the vocabulary size is |V| = 1000 words, compute the Laplace-smoothed probability P('prize' | Ham).

Step 1: Identify given parameters:

Count('prize', Ham) = 0

Total words in Ham documents = N_Ham = 800 words

Vocabulary size |V| = 1000 words

Step 2: Apply Laplace Add-1 Smoothing formula:

P('prize' | Ham) = [ Count('prize', Ham) + 1 ] / [ N_Ham + |V| ]

Step 3: Substitute values:

P('prize' | Ham) = (0 + 1) / (800 + 1000) = 1 / 1800 ≈ 0.000556.

Conclusion: Without Laplace smoothing, P('prize' | Ham) would be 0, zeroing out the entire posterior probability Product.

WORKED NUMERICAL · STUDENT DERIVATION✎ Key Takeaway: With several words, Naive Bayes multiplies their likelihoods, assuming the words are independent given the class.

Worked example: one-word Naive Bayes

Problem Statement:
40% of emails are spam. The word 'free' appears in 50% of spam and 10% of non-spam. An email contains 'free'. What is P(spam | free)?
Step 1: Spam path

P(spam)·P(free | spam).

0.4·0.5
↳ Result: 0.20
Step 2: Ham path

P(ham)·P(free | ham).

0.6·0.1
↳ Result: 0.06
Step 3: Normalise

0.20/(0.20 + 0.06).

≈ 0.769
Final Answer:≈ 0.769
STUDENT PRACTICE · CONCEPT DRILL

Practice: test yourself

Original practice questions in the GATE style, with worked explanations. Not past-paper questions.

Problem 1 · FOUNDATION

In k-NN, a very small k (like k = 1) gives:

Problem 2 · GATE-LEVEL

Why does k-NN need feature scaling?

Problem 3 · GATE-LEVEL

Laplace smoothing in Naive Bayes stops:

SOURCE TRANSPARENCY & CITATIONS

Primary Academic References & Exam Sources

Every concept in Notes From a B.Tech Brain is synthesized from authoritative academic texts, seminal peer-reviewed research, verified exam archives, and renowned university lectures.

Curated University Lecture Series
Pattern Recognition and Machine Learning ·
LECTURE SERIES