Naive Bayes ML Lecture
- 31Unfamiliar
- 0Learning
- 0Familiar
- 0Mastered
What is the primary task of a classification algorithm?
What is the primary task of a classification algorithm?
31 questions
- 1
What is the primary task of a classification algorithm?
- A
Predicting a continuous numerical value
- B
Estimating the probability density of inputs
- C
Predicting one of a small set of discrete classes
- D
Clustering data into groups without labels
Correct answer
CPredicting one of a small set of discrete classes
Explanation
Classification involves predicting a categorical label (e.g., 0 or 1) from input features. Other options describe regression, clustering, and density estimation.
- A
- 2
In the lecture, what does the superscript i in x(i) denote?
- A
The ith dimension of the output
- B
The index of the iteration in training
- C
The ith feature of the input vector
- D
The ith training example
Correct answer
DThe ith training example
Explanation
Superscript i indexes the training example, while subscript j would index the feature within that example.
- A
- 3
What does the bold notation x represent in the context of the lecture?
- A
The output label
- B
A vector of input features
- C
A scalar random variable
- D
The number of training examples
Correct answer
BA vector of input features
Explanation
x is a vector because it contains multiple features (e.g., whether a user likes each movie). It is bold to indicate it is a vector.
- A
- 4
In the notation xj(i), what does the subscript j represent?
- A
The jth feature of the ith training example
- B
The jth training example
- C
The jth parameter of the model
- D
The jth output label
Correct answer
AThe jth feature of the ith training example
Explanation
Subscript j indexes the feature within the input vector for the ith training example.
- A
- 5
What is the key difference between brute-force Bayes and naive Bayes?
- A
Brute-force Bayes uses MLE while naive Bayes uses MAP
- B
Naive Bayes assumes features are independent given the class, while brute-force Bayes does not
- C
Naive Bayes requires more training data than brute-force Bayes
- D
Brute-force Bayes can handle continuous features, while naive Bayes cannot
Correct answer
BNaive Bayes assumes features are independent given the class, while brute-force Bayes does not
Explanation
Brute-force Bayes models the full joint distribution P(x∣y), leading to exponential parameters. Naive Bayes simplifies by assuming conditional independence of features given the class.
- A
- 6
Why does brute-force Bayes become impractical for large numbers of binary features?
- A
It always produces probabilities of zero
- B
It requires O(2m) parameters, which grows exponentially with the number of features m
- C
It requires a separate test set for each feature
- D
It cannot be implemented using counting
Correct answer
BIt requires O(2m) parameters, which grows exponentially with the number of features m
Explanation
For m binary features, the conditional probability table for P(x∣y) has 2m entries, and with two classes that is 2m+1 parameters, which is infeasible for large m.
- A
- 7
The naive Bayes assumption states that:
- A
The class label is independent of the features
- B
All features are independent of each other
- C
Features are conditionally independent given the class label
- D
All features are independent of the class label
Correct answer
CFeatures are conditionally independent given the class label
Explanation
Naive Bayes assumes P(x∣y)=∏j=1mP(xj∣y), i.e., features are independent given the class. This is a simplifying assumption that may not hold in reality.
- A
- 8
In naive Bayes, the prediction rule is:
- A
y^=argmaxyP(x∣y)P(y)
- B
y^=argmaxyP(y)
- C
y^=argmaxyP(x∣y)
- D
y^=argmaxyP(y∣x)
Correct answer
Ay^=argmaxyP(x∣y)P(y)
Explanation
Using Bayes' theorem and dropping the denominator (constant for argmax), the prediction is y^=argmaxyP(x∣y)P(y). With the naive Bayes assumption, P(x∣y) becomes ∏jP(xj∣y).
- A
- 9
Why can we ignore the denominator P(x) when making predictions with naive Bayes?
- A
Because P(x) does not depend on the class y, so it doesn't affect the argmax
- B
Because P(x) is always equal to 1
- C
Because P(x) is the same for all training examples
- D
Because P(x) is canceled by the numerator
Correct answer
ABecause P(x) does not depend on the class y, so it doesn't affect the argmax
Explanation
The denominator P(x) is constant with respect to y, so it does not affect which y maximizes the expression.
- A
- 10
In naive Bayes, how are the parameters estimated using maximum likelihood estimation (MLE)?
- A
By solving a system of linear equations
- B
By counting frequencies in the training data
- C
By gradient descent on the log-likelihood
- D
By computing the mode of a Beta distribution
Correct answer
BBy counting frequencies in the training data
Explanation
MLE for naive Bayes parameters (e.g., P(y) and P(xj∣y)) is simply counting the relative frequencies in the training data.
- A
- 11
What problem does Laplace smoothing (MAP with Beta(2,2) prior) address in naive Bayes?
- A
Zero probabilities that can arise from MLE when a feature never appears for a class
- B
Overfitting due to too many parameters
- C
Slow training time on large datasets
- D
Underflow when multiplying many probabilities
Correct answer
AZero probabilities that can arise from MLE when a feature never appears for a class
Explanation
If a feature never occurs for a class in the training data, MLE would estimate P(xj∣y)=0, which would make the entire product zero. Laplace smoothing adds one imaginary success and one failure to avoid zero probabilities.
- A
- 12
What is the Laplace smoothing estimate for P(xj=1∣y=1) when using a Beta(2,2) prior?
- A
count(y=1)count(xj=1,y=1)+1
- B
count(y=1)count(xj=1,y=1)
- C
count(y=1)+2count(xj=1,y=1)+1
- D
count(y=1)+4count(xj=1,y=1)+2
Correct answer
Ccount(y=1)+2count(xj=1,y=1)+1
Explanation
Laplace smoothing corresponds to a Beta(2,2) prior, which adds 1 to the numerator (imaginary success) and 2 to the denominator (imaginary total trials for that class).
- A
- 13
In the context of naive Bayes, what does the term 'training is just counting' mean?
- A
The training process involves only arithmetic operations
- B
The algorithm counts the number of features to determine the model complexity
- C
Parameter estimates are obtained by counting occurrences in the training data
- D
Training requires counting the number of iterations until convergence
Correct answer
CParameter estimates are obtained by counting occurrences in the training data
Explanation
Both MLE and MAP (with Laplace smoothing) estimates for probabilities in naive Bayes are computed by counting frequencies (and adding pseudocounts for MAP).
- A
- 14
When using log probabilities instead of raw probabilities in naive Bayes, which of the following is correct?
- A
The argmax over y remains the same because log is monotonic
- B
Log probabilities require adding a constant to avoid underflow
- C
Log probabilities cannot be used because they are negative
- D
The argmax over y changes because log is a monotonic transformation
Correct answer
AThe argmax over y remains the same because log is monotonic
Explanation
Since the logarithm is a monotonically increasing function, the argmax of P(y∣x) is the same as the argmax of logP(y∣x). Using logs helps avoid numerical underflow from multiplying many small probabilities.
- A
- 15
What is the purpose of a test set in machine learning classification?
- A
To evaluate the model's performance on unseen data
- B
To select which features to use
- C
To train the model parameters
- D
To tune hyperparameters like the Laplace smoothing parameter
Correct answer
ATo evaluate the model's performance on unseen data
Explanation
A test set is held out from training and used to evaluate how well the model generalizes to new, unseen data.
- A
- 16
In classification, what does 'precision' measure?
- A
Of all true positive cases, how many were predicted as positive
- B
The overall fraction of correct predictions
- C
The fraction of positive cases in the dataset
- D
Of all predicted positive cases, how many were actually positive
Correct answer
DOf all predicted positive cases, how many were actually positive
Explanation
Precision = true positives / (true positives + false positives). It answers: when the model predicts positive, how often is it correct?
- A
- 17
In classification, what does 'recall' measure?
- A
Of all predicted positive cases, how many were actually positive
- B
The overall fraction of correct predictions
- C
The fraction of negative cases that were correctly identified
- D
Of all true positive cases, how many were predicted as positive
Correct answer
DOf all true positive cases, how many were predicted as positive
Explanation
Recall = true positives / (true positives + false negatives). It answers: what fraction of actual positives did the model capture?
- A
- 18
In the spam classification example using naive Bayes, what were the features xj?
- A
The length of the email in characters
- B
The sender's email address domain
- C
Indicators of whether each word in a dictionary appeared in the email
- D
The time the email was sent
Correct answer
CIndicators of whether each word in a dictionary appeared in the email
Explanation
Features were binary indicators for each of 100,000 English words, indicating whether that word appeared in the email.
- A
- 19
Why was Laplace smoothing particularly important in the spam classification application of naive Bayes?
- A
To avoid probabilities of zero when a word never appeared in spam or ham in the training data
- B
To make the algorithm run faster at prediction time
- C
To increase the accuracy on non-spam emails
- D
To reduce training time
Correct answer
ATo avoid probabilities of zero when a word never appeared in spam or ham in the training data
Explanation
Since naive Bayes multiplies probabilities for all features, a single zero probability would make the whole product zero. Laplace smoothing ensures no probability is exactly zero.
- A
- 20
In the lecture, what was the metaphor used for a classification algorithm?
- A
A cooking recipe
- B
A GPS navigation system
- C
A library catalog system
- D
The Harry Potter Sorting Hat
Correct answer
DThe Harry Potter Sorting Hat
Explanation
The professor compared building a classification algorithm to creating a Sorting Hat that takes inputs (features) and predicts a label (house).
- A
- 21
In the context of the lecture, what does MAP stand for and what is its key difference from MLE?
- A
Mean Average Precision; it measures model performance
- B
Maximum a Posteriori; it uses a different optimization algorithm
- C
Maximum A Priori; it ignores the data likelihood
- D
Maximum a Posteriori; it incorporates a prior distribution over parameters
Correct answer
DMaximum a Posteriori; it incorporates a prior distribution over parameters
Explanation
MAP estimation maximizes the posterior P(θ∣data), which includes a prior P(θ). MLE maximizes only the likelihood P(data∣θ).
- A
- 22
What is the Beta(2,2) prior also known as?
- A
The Jeffreys prior
- B
The Laplace prior
- C
The uniform prior
- D
The Gaussian prior
Correct answer
BThe Laplace prior
Explanation
Beta(2,2) corresponds to one imaginary success and one imaginary failure, and is called the Laplace prior.
- A
- 23
When estimating P(y=1) with Laplace smoothing (Beta(2,2) prior), what is the formula?
- A
n+4count(y=1)+2
- B
n+1count(y=1)+1
- C
ncount(y=1)
- D
n+2count(y=1)+1
Correct answer
Dn+2count(y=1)+1
Explanation
With Beta(2,2), we add 1 to the count of successes and 2 to the total count (since the prior adds one success and one failure). Here n is total number of examples.
- A
- 24
In the brute-force Bayes approach with 100 binary features, how many parameters are needed for the conditional distribution P(x∣y)?
- A
2100×2=2101
- B
100
- C
100×2=200
- D
2100
Correct answer
A2100×2=2101
Explanation
For m=100 binary features, P(x∣y) has 2100 possible combinations. With two classes, that's 2101 parameters. (Note: technically 2100 for each class, so total 2×2100=2101.)
- A
- 25
What is the role of the normalization constant P(x) in Bayes' theorem for classification?
- A
It is used to compute the MAP estimate
- B
It ensures the posterior is a valid probability distribution
- C
It is the prior probability of the class
- D
It is the likelihood of the data given the class
Correct answer
BIt ensures the posterior is a valid probability distribution
Explanation
P(x) normalizes the posterior so that ∑yP(y∣x)=1. It is constant with respect to y and thus can be ignored when comparing P(y∣x) for different y.
- A
- 26
In the lecture, what was the 'Friday story' about?
- A
The professor's daughter who was born deaf and received cochlear implants
- B
The history of Stanford's electrical engineering department
- C
A hiking trip in the mountains
- D
The professor's experience with a broken car
Correct answer
AThe professor's daughter who was born deaf and received cochlear implants
Explanation
The professor shared a personal story about his daughter being born unable to hear and her subsequent cochlear implants, which were developed at Stanford.
- A
- 27
According to the lecture, what is the 'big O' order of the number of parameters in brute-force Bayes with m binary features?
- A
O(m2)
- B
O(m)
- C
O(logm)
- D
O(2m)
Correct answer
DO(2m)
Explanation
The number of parameters grows as 2m for the conditional distribution P(x∣y), leading to exponential complexity.
- A
- 28
In the context of the lecture, what is a 'feature'?
- A
A measure of model accuracy
- B
A single input variable used for prediction
- C
An output label
- D
A type of machine learning algorithm
Correct answer
BA single input variable used for prediction
Explanation
A feature is an individual measurable property or characteristic of the data, e.g., whether a user likes a particular movie.
- A
- 29
What does the notation y^ typically represent in classification?
- A
The true label
- B
The number of classes
- C
The probability of the positive class
- D
The predicted label
Correct answer
DThe predicted label
Explanation
y^ denotes the prediction made by the model, as opposed to the true label y.
- A
- 30
In the lecture's movie example, if a new user likes Independence Day but not Zootopia, and the naive Bayes model predicts they will like Life is Beautiful, which expression for y had the larger value in the argmax?
- A
P(y=0)P(x1=1∣y=0)P(x2=1∣y=0)
- B
P(y=1)P(x1=1∣y=1)P(x2=0∣y=1)
- C
P(y=0)P(x1=1∣y=0)P(x2=0∣y=0)
- D
P(y=1)P(x1=0∣y=1)P(x2=0∣y=1)
Correct answer
BP(y=1)P(x1=1∣y=1)P(x2=0∣y=1)
Explanation
The prediction is y^=argmaxyP(y)∏jP(xj∣y). For the given inputs x1=1,x2=0, we evaluate both y=0 and y=1. The lecture's example showed that y=1 yielded a larger product, so the model predicted they would like Life is Beautiful.
- A
- 31
In the lecture, what was the main reason for using MAP with Laplace smoothing over MLE in the spam filter?
- A
MAP provides probabilities instead of class labels
- B
MAP is faster to compute than MLE
- C
MAP avoids zero probabilities that could arise from MLE
- D
MAP always gives higher accuracy than MLE
Correct answer
CMAP avoids zero probabilities that could arise from MLE
Explanation
MLE can assign zero probability to words that never appear in spam or ham in the training set, which would make the entire product zero. Laplace smoothing prevents this by adding pseudocounts.
- A

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