1. Home
  2. Explore
  3. Computer Science
  4. Naive Bayes ML Lecture

Study methods

Flashcards
Quiz
Fill in the blanks
Written test
Lesson
Notes
Podcast
Content

Naive Bayes ML Lecture

  • 25Unfamiliar
  • 0Learning
  • 0Familiar
  • 0Mastered
Topic: Parameter Estimation (MLE and MAP)

What is the fundamental difference between maximum likelihood estimation (MLE) and maximum a posteriori estimation (MAP)?

25 questions

  1. 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)P(\text{data} | \text{parameters})P(data∣parameters), finding parameters that make data most probable. MAP maximizes P(parameters∣data)∝P(data∣parameters)⋅P(parameters)P(\text{parameters} | \text{data}) \propto P(\text{data} | \text{parameters}) \cdot P(\text{parameters})P(parameters∣data)∝P(data∣parameters)⋅P(parameters), incorporating a prior distribution to express initial beliefs.

  2. 2

    In MAP estimation, what additional term appears compared to MLE?

    Model answer

    MAP adds a prior probability term P(parameters)P(\text{parameters})P(parameters) that multiplies the likelihood, reflecting how likely the parameter values were before seeing any data.

    Explanation

    The MAP objective is arg⁡max⁡θlog⁡P(data∣θ)+log⁡P(θ)\arg\max_\theta \log P(\text{data}|\theta) + \log P(\theta)argmaxθ​logP(data∣θ)+logP(θ), where P(θ)P(\theta)P(θ) is the prior. MLE only considers log⁡P(data∣θ)\log P(\text{data}|\theta)logP(data∣θ).

  3. 3

    For a Bernoulli parameter ppp, what is the MAP estimate using a Beta(2,2) prior, given sss successes and fff failures?

    Model answer

    The MAP estimate is s+1s+f+2\frac{s+1}{s+f+2}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\alpha = s+2α=s+2, β=f+2\beta = f+2β=f+2. The mode (MAP estimate) is α−1α+β−2=s+1s+f+2\frac{\alpha-1}{\alpha+\beta-2} = \frac{s+1}{s+f+2}α+β−2α−1​=s+f+2s+1​.

  4. 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\alpha=2α=2, β=2\beta=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. 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 ppp is the mode of the posterior Beta distribution, which is calculated as α−1α+β−2\frac{\alpha-1}{\alpha+\beta-2}α+β−2α−1​ for α>1,β>1\alpha>1, \beta>1α>1,β>1.

    Explanation

    For a binomial likelihood with Beta prior, the posterior is also Beta. MAP selects the value of ppp that maximizes posterior density, which is the distribution's mode.

  6. 6

    Define the classification task in terms of inputs and outputs.

    Model answer

    Classification is the task of predicting a discrete label yyy (usually binary, 0 or 1) from a vector of input features x=(x1,…,xm)\mathbf{x} = (x_1, \dots, x_m)x=(x1​,…,xm​). Training data consists of labeled examples (x(i),y(i))(\mathbf{x}^{(i)}, y^{(i)})(x(i),y(i)).

    Explanation

    The goal is to build a classifier that maps inputs to outputs. Each input vector contains mmm features, and the output yyy is the class label (e.g., spam or not spam).

  7. 7

    Explain the notation xi(j)x_i^{(j)}xi(j)​ and yiy_iyi​ in a training dataset.

    Model answer

    xi(j)x_i^{(j)}xi(j)​ denotes the value of the jjj-th feature for the iii-th training example. yiy_iyi​ is the true label for that example.

    Explanation

    Superscript (i)(i)(i) indexes training examples, subscript jjj indexes features. So x2(5)x_2^{(5)}x2(5)​ is the value of feature 2 for example 5.

  8. 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\mathbf{x}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 mmm.

  9. 9

    Why is the input vector x\mathbf{x}x often written in bold?

    Model answer

    Bold notation indicates that x\mathbf{x}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)\mathbf{x}^{(i)}x(i) is the vector of features for the iii-th example.

  10. 10

    Describe the Brute Force Bayes classifier.

    Model answer

    Brute Force Bayes predicts the label yyy by computing y^=arg⁡max⁡yP(y∣x)\hat{y} = \arg\max_y P(y|\mathbf{x})y^​=argmaxy​P(y∣x) using Bayes' rule: P(y∣x)∝P(x∣y)P(y)P(y|\mathbf{x}) \propto P(\mathbf{x}|y) P(y)P(y∣x)∝P(x∣y)P(y), and ignoring the normalizing constant P(x)P(\mathbf{x})P(x). It estimates a full joint distribution P(x∣y)P(\mathbf{x}|y)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)O(2^m)O(2m) parameters to represent P(x∣y)P(\mathbf{x}|y)P(x∣y) for each possible combination of feature values.

  11. 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)O(2^m)O(2m), which is computationally infeasible for large mmm (e.g., m=100m=100m=100 leads to more parameters than atoms in the universe).

    Explanation

    Each distinct combination of feature values requires a separate parameter. For mmm binary features, there are 2m2^m2m possible input patterns for each class, leading to an enormous parameter space.

  12. 12

    In Brute Force Bayes, why can we ignore the denominator P(x)P(\mathbf{x})P(x) when taking the argmax over yyy?

    Model answer

    P(x)P(\mathbf{x})P(x) is constant with respect to yyy because it does not depend on the class label. Therefore, removing it does not change which yyy maximizes the expression.

    Explanation

    The argmax operation only cares about relative values across different yyy. Since P(x)P(\mathbf{x})P(x) is the same for all yyy, it can be omitted from the optimization.

  13. 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 yyy: P(x∣y)=∏i=1mP(xi∣y)P(\mathbf{x}|y) = \prod_{i=1}^m P(x_i|y)P(x∣y)=∏i=1m​P(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. 14

    What computational benefit does the naive Bayes assumption provide?

    Model answer

    It reduces the number of parameters from exponential (O(2m)O(2^m)O(2m)) to linear (O(m)O(m)O(m)) by decomposing the joint probability P(x∣y)P(\mathbf{x}|y)P(x∣y) into a product of feature-wise conditional probabilities P(xi∣y)P(x_i|y)P(xi​∣y).

    Explanation

    Instead of needing a parameter for every combination of feature values, we only need 2m2m2m parameters (for each feature and each class) to define the full conditional distribution under independence.

  15. 15

    How do you estimate P(y)P(y)P(y) from training data using MLE?

    Model answer

    P(y=c)P(y = c)P(y=c) is estimated as the fraction of training examples with label ccc: count(y=c)n\frac{\text{count}(y=c)}{n}ncount(y=c)​, where nnn 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. 16

    How do you estimate P(xi=1∣y=c)P(x_i = 1 | y = c)P(xi​=1∣y=c) using MLE?

    Model answer

    It is estimated as the fraction of training examples with label ccc that also have xi=1x_i = 1xi​=1: count(xi=1,y=c)count(y=c)\frac{\text{count}(x_i=1, y=c)}{\text{count}(y=c)}count(y=c)count(xi​=1,y=c)​.

    Explanation

    We take the subset of data where y=cy=cy=c, then compute the proportion where feature iii is 1.

  17. 17

    How does MAP with Laplace smoothing modify the MLE estimate for P(xi=1∣y=c)P(x_i = 1 | y = c)P(xi​=1∣y=c)?

    Model answer

    MAP with Laplace smoothing adds one imaginary success and one imaginary failure, resulting in count(xi=1,y=c)+1count(y=c)+2\frac{\text{count}(x_i=1, y=c) + 1}{\text{count}(y=c) + 2}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. 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)\prod_i P(x_i|y)∏i​P(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)=0P(\text{word}|\text{spam})=0P(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. 19

    In the context of spam classification, how were features defined?

    Model answer

    Each feature xix_ixi​ indicated whether a specific word (from a large dictionary of English words) was present or absent in the email.

    Explanation

    The input vector x\mathbf{x}x had a dimension for each word (e.g., 100,000 words). xi=1x_i=1xi​=1 if the iii-th word appeared in the email, 0 otherwise.

  20. 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. 21

    How do you make a prediction for a new example using a trained naive Bayes model?

    Model answer

    Compute y^=arg⁡max⁡y[log⁡P(y)+∑i=1mlog⁡P(xi∣y)]\hat{y} = \arg\max_y \left[ \log P(y) + \sum_{i=1}^m \log P(x_i|y) \right]y^​=argmaxy​[logP(y)+∑i=1m​logP(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 yyy of the log-posterior (ignoring constant denominator) yields the predicted class.

  22. 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., mmm features) can cause floating-point underflow. Using logarithms converts multiplication to addition, which is numerically stable.

    Explanation

    For large mmm, the product ∏iP(xi∣y)\prod_i P(x_i|y)∏i​P(xi​∣y) may underflow to zero in finite precision. The sum of logs is more robust and does not lose precision.

  23. 23

    Define accuracy, precision, and recall in the context of binary classification.

    Model answer

    Accuracy = TP+TNTP+TN+FP+FN\frac{TP+TN}{TP+TN+FP+FN}TP+TN+FP+FNTP+TN​, Precision = TPTP+FP\frac{TP}{TP+FP}TP+FPTP​, Recall = TPTP+FN\frac{TP}{TP+FN}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. 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. 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.

1 of 25
Question 1 of 25

Ask anything

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

FlashcardsQuizFill in the blanksWritten testLessonNotesPodcastContent