Naive Bayes ML Lecture
- 25Unfamiliar
- 0Learning
- 0Familiar
- 0Mastered
What is the fundamental difference between maximum likelihood estimation (MLE) and maximum a posteriori estimation (MAP)?
25 questions
- 1
What is the fundamental difference between maximum likelihood estimation (MLE) and maximum a posteriori estimation (MAP)?
Model answer
MLE selects parameter values that maximize the likelihood of the observed data, while MAP selects parameter values that maximize the posterior probability, which includes a prior term representing the belief about the parameters before seeing data.
Explanation
MLE maximizes P(data∣parameters), finding parameters that make data most probable. MAP maximizes P(parameters∣data)∝P(data∣parameters)⋅P(parameters), incorporating a prior distribution to express initial beliefs.
- 2
In MAP estimation, what additional term appears compared to MLE?
Model answer
MAP adds a prior probability term P(parameters) that multiplies the likelihood, reflecting how likely the parameter values were before seeing any data.
Explanation
The MAP objective is argmaxθlogP(data∣θ)+logP(θ), where P(θ) is the prior. MLE only considers logP(data∣θ).
- 3
For a Bernoulli parameter p, what is the MAP estimate using a Beta(2,2) prior, given s successes and f failures?
Model answer
The MAP estimate is s+f+2s+1.
Explanation
With a Beta(2,2) prior (Laplace prior, representing one imaginary success and one imaginary failure), the posterior Beta has parameters α=s+2, β=f+2. The mode (MAP estimate) is α+β−2α−1=s+f+2s+1.
- 4
What is the Laplace prior and why is it commonly used?
Model answer
The Laplace prior is a Beta(2,2) distribution, which adds one imaginary success and one imaginary failure. It ensures that estimated probabilities never become exactly 0 or 1, avoiding division by zero and degenerate cases.
Explanation
Beta(2,2) has α=2, β=2, meaning one prior success and one prior failure. This introduces a small amount of smoothing, preventing zero probabilities that could arise from insufficient data.
- 5
How does the mode of the posterior Beta distribution relate to MAP estimation for a binomial proportion?
Model answer
The MAP estimate for a binomial proportion p is the mode of the posterior Beta distribution, which is calculated as α+β−2α−1 for α>1,β>1.
Explanation
For a binomial likelihood with Beta prior, the posterior is also Beta. MAP selects the value of p that maximizes posterior density, which is the distribution's mode.
- 6
Define the classification task in terms of inputs and outputs.
Model answer
Classification is the task of predicting a discrete label y (usually binary, 0 or 1) from a vector of input features x=(x1,…,xm). Training data consists of labeled examples (x(i),y(i)).
Explanation
The goal is to build a classifier that maps inputs to outputs. Each input vector contains m features, and the output y is the class label (e.g., spam or not spam).
- 7
Explain the notation xi(j) and yi in a training dataset.
Model answer
xi(j) denotes the value of the j-th feature for the i-th training example. yi is the true label for that example.
Explanation
Superscript (i) indexes training examples, subscript j indexes features. So x2(5) is the value of feature 2 for example 5.
- 8
What is meant by 'features' in a classification problem?
Model answer
Features are the individual measurable properties or attributes of the input data, represented as components of the input vector x. For example, in movie recommendation, features might be whether a user liked each of a set of movies.
Explanation
Features are the building blocks of the input. In binary problems, each feature is typically 0 or 1 (e.g., presence of a word). The number of features is denoted by m.
- 9
Why is the input vector x often written in bold?
Model answer
Bold notation indicates that x is a vector (a list of multiple values) rather than a scalar.
Explanation
In machine learning, inputs are multi-dimensional. Boldface distinguishes vectors from scalars. For instance, x(i) is the vector of features for the i-th example.
- 10
Describe the Brute Force Bayes classifier.
Model answer
Brute Force Bayes predicts the label y by computing y^=argmaxyP(y∣x) using Bayes' rule: P(y∣x)∝P(x∣y)P(y), and ignoring the normalizing constant P(x). It estimates a full joint distribution P(x∣y) for each class.
Explanation
The classifier directly models the probability of the label given the input. For binary features, it requires O(2m) parameters to represent P(x∣y) for each possible combination of feature values.
- 11
What is the main problem with Brute Force Bayes when there are many binary features?
Model answer
The number of parameters grows exponentially with the number of features, O(2m), which is computationally infeasible for large m (e.g., m=100 leads to more parameters than atoms in the universe).
Explanation
Each distinct combination of feature values requires a separate parameter. For m binary features, there are 2m possible input patterns for each class, leading to an enormous parameter space.
- 12
In Brute Force Bayes, why can we ignore the denominator P(x) when taking the argmax over y?
Model answer
P(x) is constant with respect to y because it does not depend on the class label. Therefore, removing it does not change which y maximizes the expression.
Explanation
The argmax operation only cares about relative values across different y. Since P(x) is the same for all y, it can be omitted from the optimization.
- 13
State the naive Bayes assumption and explain why it is considered 'naive'.
Model answer
The naive Bayes assumption states that the features are conditionally independent given the class label y: P(x∣y)=∏i=1mP(xi∣y). It is 'naive' because this independence is usually unrealistic in real data (e.g., movie preferences are correlated).
Explanation
Conditional independence assumes that knowing the class label makes the features unrelated. For example, knowing someone likes 'Life is Beautiful' should make their liking of 'Independence Day' independent of liking 'Zootopia', which is often false.
- 14
What computational benefit does the naive Bayes assumption provide?
Model answer
It reduces the number of parameters from exponential (O(2m)) to linear (O(m)) by decomposing the joint probability P(x∣y) into a product of feature-wise conditional probabilities P(xi∣y).
Explanation
Instead of needing a parameter for every combination of feature values, we only need 2m parameters (for each feature and each class) to define the full conditional distribution under independence.
- 15
How do you estimate P(y) from training data using MLE?
Model answer
P(y=c) is estimated as the fraction of training examples with label c: ncount(y=c), where n is the total number of training examples.
Explanation
MLE simply counts the occurrences of each class in the training set and normalizes by total examples.
- 16
How do you estimate P(xi=1∣y=c) using MLE?
Model answer
It is estimated as the fraction of training examples with label c that also have xi=1: count(y=c)count(xi=1,y=c).
Explanation
We take the subset of data where y=c, then compute the proportion where feature i is 1.
- 17
How does MAP with Laplace smoothing modify the MLE estimate for P(xi=1∣y=c)?
Model answer
MAP with Laplace smoothing adds one imaginary success and one imaginary failure, resulting in count(y=c)+2count(xi=1,y=c)+1.
Explanation
Laplace smoothing corresponds to a Beta(2,2) prior, which prevents zero probabilities. The denominator increases by 2 (one for each possible outcome) and numerator by 1 for the specific outcome.
- 18
Why is Laplace smoothing considered important in naive Bayes?
Model answer
Laplace smoothing ensures that no estimated probability is exactly 0 or 1. A zero probability in the product ∏iP(xi∣y) would make the entire product zero, eliminating the influence of all other features and potentially misclassifying the example.
Explanation
For example, if a word never appears in spam emails during training, MLE gives P(word∣spam)=0, causing any email containing that word to have zero spam probability under naive Bayes, even if other words strongly indicate spam.
- 19
In the context of spam classification, how were features defined?
Model answer
Each feature xi indicated whether a specific word (from a large dictionary of English words) was present or absent in the email.
Explanation
The input vector x had a dimension for each word (e.g., 100,000 words). xi=1 if the i-th word appeared in the email, 0 otherwise.
- 20
Why was MAP with Laplace smoothing particularly useful for spam filtering?
Model answer
It avoided zero probabilities for words not seen in the training data for a certain class (spam or non-spam). Without smoothing, a new word in an email would make the product zero, undermining classification.
Explanation
Spam filters must handle unseen words. Laplace smoothing ensures that even for new words, the conditional probability is small but non-zero, allowing other features to contribute to the decision.
- 21
How do you make a prediction for a new example using a trained naive Bayes model?
Model answer
Compute y^=argmaxy[logP(y)+∑i=1mlogP(xi∣y)] to select the class with the highest posterior log-probability.
Explanation
Using logarithms avoids numerical underflow when multiplying many small probabilities. The argmax over y of the log-posterior (ignoring constant denominator) yields the predicted class.
- 22
Why is it common to use log probabilities instead of raw probabilities in naive Bayes predictions?
Model answer
Multiplying many small probabilities (e.g., m features) can cause floating-point underflow. Using logarithms converts multiplication to addition, which is numerically stable.
Explanation
For large m, the product ∏iP(xi∣y) may underflow to zero in finite precision. The sum of logs is more robust and does not lose precision.
- 23
Define accuracy, precision, and recall in the context of binary classification.
Model answer
Accuracy = TP+TN+FP+FNTP+TN, Precision = TP+FPTP, Recall = TP+FNTP, where TP=true positives, TN=true negatives, FP=false positives, FN=false negatives.
Explanation
Accuracy measures overall correctness. Precision measures how many predicted positives are actually positive. Recall measures how many actual positives are correctly identified.
- 24
Why might precision be considered more important than recall in spam detection?
Model answer
High precision ensures that legitimate emails are rarely misclassified as spam (low false positive rate). Users are more tolerant of spam in their inbox (lower recall) than losing important emails to the spam folder.
Explanation
False positives (labeling real email as spam) are costly because important messages may be missed. Users typically prioritize avoiding false positives over capturing every spam email.
- 25
What is the purpose of a held-out test set in machine learning?
Model answer
A held-out test set is used to evaluate the model's performance on unseen data, providing an estimate of how well the model generalizes to new examples not used during training.
Explanation
Training data is used to learn parameters, but performance on training data can be overoptimistic. A separate test set, with known labels, allows unbiased assessment of accuracy, precision, recall, etc.

Ask anything
We've read this whole study set, so questions about it get the best answers.