Naive Bayes and generative models: past questions

37 questions · 94.5 marks · 10 papers. Try each one before checking.

Solve them and check answers →Read the notes first

Aug 2023 (day not given)

Question Q10 SA · 2.5 marks

A binary classification dataset contains only one feature and the data points given the label follow the Gaussian distributions whose means and variances are already estimated as $x\mid(y=0)\sim N(0,1)$ and $x\mid(y=1)\sim N(2,2)$. What will be the prediction for the point $x=1$? Assume that $\hat p$, an estimate for $P(y=1)$, is $0.5$.

Type your answer on the interactive page.

Question Q16 MCQ · 2 marks

Consider a probability distribution over $(X,y)$ where features are one-dimensional and $y\in\{+1,-1\}$. Let $X\mid(y=1)$ follow a uniform distribution over $[0,4]$ and $X\mid(y=-1)$ follow a uniform distribution over $[2,4]$.
Let $x=2$ and let $\hat p$ be the estimate for $p=P(y=1)$. Find conditions on $\hat p$ such that the Bayes classifier predicts $1$ for this $x$. Consider that the tie-breaker is predicted in class $1$.
  1. $\hat p\le\frac14$
  2. $\hat p\ge\frac14$
  3. $\hat p\le\frac23$
  4. $\hat p\ge\frac23$

Question Q15 SA · 2 marks

Consider a probability distribution over $(X,y)$ where features are one-dimensional and $y\in\{+1,-1\}$. Let $X\mid(y=1)$ follow a uniform distribution over $[0,4]$ and $X\mid(y=-1)$ follow a uniform distribution over $[2,4]$.
If $p=P(y=1)$ is estimated to be $0.4$, what will be the prediction for the point $x=3$ using the Bayes classifier? Enter $1$ or $-1$.

Type your answer on the interactive page.

Question Q17 SA · 2 marks

Consider a probability distribution over $(X,y)$ where features are one-dimensional and $y\in\{+1,-1\}$. Let $X\mid(y=1)$ follow a uniform distribution over $[0,4]$ and $X\mid(y=-1)$ follow a uniform distribution over $[2,4]$.
If $p=P(y=1)$ is estimated to be $0.5$ using MLE on a given training dataset, what will be the training error of the Bayes classifier for this problem?

Type your answer on the interactive page.

Question Q19 SA · 2 marks

A naive Bayes model is trained on the data matrix $X$ of shape $(d,n)$ and label vector $y$: $X=\begin{bmatrix}1&0&0&0\\0&1&0&0\\0&1&1&0\end{bmatrix}$, $y=[1,0,1,0]^T$. Assume $\hat p$ and $\hat p_j^{\,y_i}$ are estimates for $P(y=1)$ and $P(f_j=1\mid y=y_i)$, where $f_i$ is the $i^{\text{th}}$ feature. These parameters are estimated using MLE. Do not apply any smoothing.
Calculate the value of $\hat p_2^{\,0}$.

Type your answer on the interactive page.

Question Q20 SA · 2 marks

A naive Bayes model is trained on the data matrix $X$ of shape $(d,n)$ and label vector $y$: $X=\begin{bmatrix}1&0&0&0\\0&1&0&0\\0&1&1&0\end{bmatrix}$, $y=[1,0,1,0]^T$. Assume $\hat p$ and $\hat p_j^{\,y_i}$ are estimates for $P(y=1)$ and $P(f_j=1\mid y=y_i)$, where $f_i$ is the $i^{\text{th}}$ feature. These parameters are estimated using MLE. Do not apply any smoothing.
Calculate the value of $\hat p_2^{\,1}$.

Type your answer on the interactive page.

Aug 2025 (03 Aug)

Question Q9 MSQ · 2 marks

Which among the following are true?
  1. In generative model, we are interested in how the features are generated.
  2. In discriminative model, we are interested in how the features are generated.
  3. In discriminative model, we are interested in modelling $p(y\mid x)$ where $y$ is the label and $x$ is a feature.
  4. In generative model, we are interested in modelling $p(y\mid x)$, where $y$ is the label and $x$ is a feature.
  5. Gaussian Naive Bayes is a discriminative model.

Question Q15 SA · 2 marks

Consider a 2-class Naive Bayes classifier with the first feature $f_1$ binary and the second feature $f_2$ Gaussian. Estimate of $P(Y=1)$: $\hat p=0.4$. Estimate of $P(f_1=1\mid y=0)$: $\hat p_1^{\,0}=0.4$. Estimate of $P(f_1=1\mid y=1)$: $\hat p_1^{\,1}=0.5$. $(f_2\mid y=0)\sim\text{Normal}(0,1)$ and $(f_2\mid y=1)\sim\text{Normal}(1,1)$.
If a test point has label $0$, what will be the probability that the point is $x_{\text{test}}=[0\ \ 0]^T$? Enter the answer correct to two decimal places.

Type your answer on the interactive page.

Question Q16 SA · 3 marks

Consider a 2-class Naive Bayes classifier with the first feature $f_1$ binary and the second feature $f_2$ Gaussian. Estimate of $P(Y=1)$: $\hat p=0.4$. Estimate of $P(f_1=1\mid y=0)$: $\hat p_1^{\,0}=0.4$. Estimate of $P(f_1=1\mid y=1)$: $\hat p_1^{\,1}=0.5$. $(f_2\mid y=0)\sim\text{Normal}(0,1)$ and $(f_2\mid y=1)\sim\text{Normal}(1,1)$.
For $x_{\text{test}}=[0\ \ 1.5]^T$ what output would the Naive Bayes model predict?

Type your answer on the interactive page.

Apr 2026 (06 Apr)

Question Q13 SA · 3 marks

You are provided with a training set of $5$ observations, each consisting of four binary features $X=\{X_1,X_2,X_3,X_4\}$ and a binary target label $Y\in\{0,1\}$.
Sample ID$X_1$$X_2$$X_3$$X_4$$Y$
110111
201100
311011
400111
510000
Using the Naive Bayes assumption and the data provided, calculate the joint probability $P(X,Y=1)$ for a new test instance $X=(1,0,1,1)$. Enter your answer correct to two decimal places.

Type your answer on the interactive page.

Question Q14 SA · 3 marks

You are provided with a training set of $5$ observations, each consisting of four binary features $X=\{X_1,X_2,X_3,X_4\}$ and a binary target label $Y\in\{0,1\}$.
Sample ID$X_1$$X_2$$X_3$$X_4$$Y$
110111
201100
311011
400111
510000
To address zero-probability estimates using Laplace smoothing, the dataset is augmented with synthetic observations. Specifically, add the following two samples to the original table: (1) one sample in which all features $(X_1,X_2,X_3,X_4)$ take the value $1$ and the class label is $Y=1$; (2) one sample in which all features take the value $1$ and the class label is $Y=0$. Based on this new augmented dataset of $7$ samples, calculate the updated conditional probability $P(X_2=1\mid Y=1)$.

Type your answer on the interactive page.

Question Q15 MCQ · 2 marks

You are provided with a training set of $5$ observations, each consisting of four binary features $X=\{X_1,X_2,X_3,X_4\}$ and a binary target label $Y\in\{0,1\}$.
Sample ID$X_1$$X_2$$X_3$$X_4$$Y$
110111
201100
311011
400111
510000
For the Naive Bayes model described in the main data with $n$ binary features and a binary class label, how many independent parameters are required to fully specify the model? Answer for the original dataset with $5$ training examples.
  1. $5$
  2. $8$
  3. $9$
  4. $10$

Aug 2026 (14 Aug)

Question Q11 SA · 4 marks

A generative classifier models the joint distribution of the feature vector $X$ and the class label $Y$. For a particular email represented by the feature vector $x$, suppose $P(X=x,Y=\text{Spam})=0.015$ and $P(X=x,Y=\text{Not Spam})=0.035$. Compute the posterior probability $P(Y=\text{Spam}\mid X=x)$.

Type your answer on the interactive page.

Question Q2 MCQ · 4 marks

Suppose an email is represented by a binary feature vector $X=(x_1,x_2,\dots,x_d)\in\{0,1\}^d$. A generative classifier first chooses the class label $Y$ according to the prior distribution $P(Y)$. It then generates the feature vector $X$ conditioned on the chosen class. The classifier assumes that, given the class label, the features are conditionally independent. Which of the following expressions correctly represents $P(Y=\text{Spam}\mid X=x)$?
  1. $\dfrac{P(Y=\text{Spam})}{P(X=x)}$
  2. $\dfrac{\left(\prod_{i=1}^dP(x_i)\right)P(Y=\text{Spam})}{P(X=x)}$
  3. $\prod_{i=1}^dP(Y=\text{Spam}\mid x_i)$
  4. $\dfrac{\left(\prod_{i=1}^dP(x_i\mid Y=\text{Spam})\right)P(Y=\text{Spam})}{P(X=x)}$

Dec 2024 (01 Dec)

Question Q10 SA · 4 marks

Suppose you want to use a Naive Bayes classifier to predict whether a student will pass or fail an exam based on two features: the number of hours they studied and whether they attended review sessions. Assume that the features are conditionally independent given the exam outcome and that the variances of the study hours distributions are equal for both pass and fail categories. How many parameters are required to classify a new student using this Naive Bayes classifier?

Type your answer on the interactive page.

Question Q6 SA · 4 marks

A binary classification dataset has $2000$ data points belonging to $\{0,1\}^2$. A Naive Bayes algorithm was run on the same dataset, resulting in the following estimates: $\hat p$, estimate for $P(y=1)$, is $0.4$; $\hat p_1^{\,0}$, estimate for $P(f_1=1\mid y=0)$, is $0.25$; $\hat p_2^{\,0}$, estimate for $P(f_2=1\mid y=0)$, is $0.35$; $\hat p_1^{\,1}$, estimate for $P(f_1=1\mid y=1)$, is $0.15$; $\hat p_2^{\,1}$, estimate for $P(f_2=1\mid y=1)$, is $0.05$.
What is the estimated value of $P(f_2=0\mid y=1)$? Write your answer correct to two decimal places.

Type your answer on the interactive page.

Question Q7 SA · 3 marks

A binary classification dataset has $2000$ data points belonging to $\{0,1\}^2$. A Naive Bayes algorithm was run on the same dataset, resulting in the following estimates: $\hat p$, estimate for $P(y=1)$, is $0.4$; $\hat p_1^{\,0}$, estimate for $P(f_1=1\mid y=0)$, is $0.25$; $\hat p_2^{\,0}$, estimate for $P(f_2=1\mid y=0)$, is $0.35$; $\hat p_1^{\,1}$, estimate for $P(f_1=1\mid y=1)$, is $0.15$; $\hat p_2^{\,1}$, estimate for $P(f_2=1\mid y=1)$, is $0.05$.
What will be the predicted label for the data point $[1,0]^T$?

Type your answer on the interactive page.

Aug 2024 (04 Aug)

Question Q29 SA · 2 marks

Consider a multi-class classification problem with $3$ classes and $4$ features, all of which are binary. A generative model is used to model the joint distribution of the features and labels.
Find the total number of independent (free) parameters in the model if the class conditional independence assumption is not enforced.

Type your answer on the interactive page.

Question Q30 SA · 2 marks

Consider a multi-class classification problem with $3$ classes and $4$ features, all of which are binary. A generative model is used to model the joint distribution of the features and labels.
Find the total number of independent (free) parameters in the model if the class conditional independence assumption is enforced.

Type your answer on the interactive page.

Question Q25 SA · 2 marks

Assume there is no smoothing. Consider the dataset for a binary classification problem with features in $\{0,1\}^3$ and labels in $\{0,1\}$: $X=\begin{bmatrix}1&0&1&1&0&1&0&0\\0&1&0&1&1&0&1&1\\1&1&0&1&0&0&1&0\end{bmatrix}$, $y=[1,1,1,1,0,0,0,0]^T$. (The bank notes that the matrix columns in the PDF text are slightly compressed: $8$ samples, $4$ with $y=1$ and $4$ with $y=0$.) A Naive Bayes classifier is trained. The parameters are $\hat p_i^{\,y}$, the probability of feature $i$ being $1$ in class $y$:
$i$$y=0$$y=1$
1$a$$b$
2$c$$d$
3$e$$f$
Find the value of $c+d$.

Type your answer on the interactive page.

Question Q26 SA · 2 marks

Assume there is no smoothing. Consider the dataset for a binary classification problem with features in $\{0,1\}^3$ and labels in $\{0,1\}$: $X=\begin{bmatrix}1&0&1&1&0&1&0&0\\0&1&0&1&1&0&1&1\\1&1&0&1&0&0&1&0\end{bmatrix}$, $y=[1,1,1,1,0,0,0,0]^T$. (The bank notes that the matrix columns in the PDF text are slightly compressed: $8$ samples, $4$ with $y=1$ and $4$ with $y=0$.) A Naive Bayes classifier is trained. The parameters are $\hat p_i^{\,y}$, the probability of feature $i$ being $1$ in class $y$:
$i$$y=0$$y=1$
1$a$$b$
2$c$$d$
3$e$$f$
Find the value of $a+c+e$.

Type your answer on the interactive page.

Question Q27 SA · 2 marks

Assume there is no smoothing. Consider the dataset for a binary classification problem with features in $\{0,1\}^3$ and labels in $\{0,1\}$: $X=\begin{bmatrix}1&0&1&1&0&1&0&0\\0&1&0&1&1&0&1&1\\1&1&0&1&0&0&1&0\end{bmatrix}$, $y=[1,1,1,1,0,0,0,0]^T$. (The bank notes that the matrix columns in the PDF text are slightly compressed: $8$ samples, $4$ with $y=1$ and $4$ with $y=0$.) A Naive Bayes classifier is trained. The parameters are $\hat p_i^{\,y}$, the probability of feature $i$ being $1$ in class $y$:
$i$$y=0$$y=1$
1$a$$b$
2$c$$d$
3$e$$f$
Find the predicted label for the test point $[0,1,0]^T$.

Type your answer on the interactive page.

Mar 2024 (24 Mar)

Question Q15 SA · 3 marks

Suppose you have a five-class classification problem where class label $y\in(0,1,2,3,4)$ and each training example $x_i$ has binary features $f_1,f_2,f_3\in(0,1)$. How many parameters do we need to know to classify an example using Naive Bayes classifier?

Type your answer on the interactive page.

Question Q9 SA · 3 marks

A naive Bayes model is trained on the data matrix $X$ of shape $(d,n)$ and label vector $y$: $X=\begin{bmatrix}1&0&0&0\\0&1&0&1\\0&1&1&0\end{bmatrix}$, $y=[1,0,1,1]^T$. Assume $\hat p$ and $\hat p_j^{\,y_i}$ are estimates for $P(y=1)$ and $P(f_j=1\mid y=y_i)$, where $f_i$ is the $i^{\text{th}}$ feature. These parameters are estimated using MLE.
Calculate the value of $\hat p_2^{\,1}$.

Type your answer on the interactive page.

Question Q10 SA · 3 marks

A naive Bayes model is trained on the data matrix $X$ of shape $(d,n)$ and label vector $y$: $X=\begin{bmatrix}1&0&0&0\\0&1&0&1\\0&1&1&0\end{bmatrix}$, $y=[1,0,1,1]^T$. Assume $\hat p$ and $\hat p_j^{\,y_i}$ are estimates for $P(y=1)$ and $P(f_j=1\mid y=y_i)$, where $f_i$ is the $i^{\text{th}}$ feature. These parameters are estimated using MLE.
Calculate the value of $\hat p_1^{\,1}$.

Type your answer on the interactive page.

Dec 2023 (day not given)

Question Q12 SA · 4 marks

Consider the problem of classifying an input text as positive sentiment or negative sentiment. For example, the text "I am happy" is positive and the text "I am a bit worried" is negative. The dictionary that is used to encode the text into a vector contains $12$ words. Suppose we prefer to use a generative learning algorithm that estimates the joint probability $P(x,y)$ where $x\in\{0,1\}^{12}$ and $y\in\{0,1\}$. Assume that the features $x_i$ in a sample are not independent given the label. How many parameters do we need to estimate from the given data? (Enter $-1$ if you think the given information is insufficient to find the answer.)

Type your answer on the interactive page.

Question Q16 SA · 3 marks

Consider the dataset with $6$ samples and labels; each sample has three binary features $f_1,f_2,f_3$.
sample$f_1$$f_2$$f_3$$y$
$x_1$1101
$x_2$0101
$x_3$1000
$x_4$0010
$x_5$1010
$x_6$1111
Assume the features are conditionally independent given the label $y$. The test sample is $x_{\text{test}}=[0,1,1]^T$.
What is the estimated probability that the test point belongs to class $0$ (that is, $p(y=0\mid x_{\text{test}})$)?

Type your answer on the interactive page.

Question Q17 SA · 3 marks

Consider the dataset with $6$ samples and labels; each sample has three binary features $f_1,f_2,f_3$.
sample$f_1$$f_2$$f_3$$y$
$x_1$1101
$x_2$0101
$x_3$1000
$x_4$0010
$x_5$1010
$x_6$1111
Assume the features are conditionally independent given the label $y$. The test sample is $x_{\text{test}}=[0,1,1]^T$.
What will be the predicted label according to the Naive Bayes decision rule?

Type your answer on the interactive page.

Mar 2025 (16 Mar)

Question Q3 MCQ · 3 marks

Consider a $k$-class classification problem with five binary features $f_1,f_2,f_3,f_4$ and $f_5$, where $k>2$. How many parameters need to be estimated to learn a Naive Bayes classifier?
  1. $5k$
  2. $6k-1$
  3. $(6k-1)^5$
  4. $3k-3$

Question Q5 MCQ · 2 marks

What is the main purpose of using Laplace smoothing in Naïve Bayes?
  1. To prevent numerical errors when calculating the variance of Gaussian features.
  2. To ensure that unseen categorical feature values receive small but nonzero probabilities.
  3. To strengthen the model's predictions by increasing the weight of certain features.
  4. To balance the likelihood values of all features before computing posterior probabilities.

Question Q10 SA · 4 marks

Consider a Naive Bayes problem with three features $f_1,f_2,f_3$ for a binary classification problem. We have a total of $6$ training samples:
Sample$f_1$$f_2$$f_3$$y$
$x_1$1010
$x_2$1010
$x_3$0010
$x_4$0001
$x_5$1011
$x_6$0101
For $x_{\text{test}}=[1,1,0]^T$ what output would the Naive Bayes model predict, assuming that no Laplacian smoothing has been done as part of the algorithm?

Type your answer on the interactive page.

Jul 2022 (day not given)

Question Q5 MCQ · 2 marks

In a binary classification problem, consider the following distribution of data-points from the training data on the unit-square. [Figure in the bank: four blue points at the corners of the unit square with counts: $10$ at $(0,0)$, $40$ at $(1,0)$, $30$ at $(0,1)$, $20$ at $(1,1)$; axes $x_1$ and $x_2$.] For instance, $20$ data-points have the feature vector $[1,1]^T$. The labels for these points is not important now. Which of the following Naive Bayes models would be the best choice for this dataset? Select the most appropriate option.
  1. Bernoulli NB
  2. Categorical NB
  3. Multinomial NB
  4. Gaussian NB

Question Q6 MCQ · 2 marks

$x=[x_1,x_2,x_3]^T$ is a feature vector and $y$ represents the label in a binary classification problem. Which of the following equations represents the "naive" assumption used in the Naive Bayes algorithm?
  1. $P(x,y)=P(y)\cdot P(x\mid y)$
  2. $P(x)=P(x_1)\cdot P(x_2)\cdot P(x_3)$
  3. $P(y\mid x)=\dfrac{P(y)\cdot P(x\mid y)}{P(x)}$
  4. $P(x\mid y)=P(x_1\mid y)\cdot P(x_2\mid y)\cdot P(x_3\mid y)$

Question Q27 SA · 1.5 marks

Consider a binary classification problem. The training-data has several features out of which we have access to only two binary features $(x_1,x_2)$. The labels are $1$ and $2$ for the two classes. The training dataset has the following distribution of points:
FeatureNumber of pointsTrue label
(0,0)301
(0,0)102
(0,1)101
(0,1)402
(1,0)301
(1,0)102
(1,1)101
(1,1)502
The first row states that there are $30$ points from class $1$ with $x_1=0,x_2=0$. A Bernoulli Naive Bayes model is fit with the matrix of probabilities $\begin{bmatrix}w_{11}&w_{12}\\w_{21}&w_{22}\end{bmatrix}$, where $w_{ij}=P(x_i=1\mid y=j)$. You can ignore smoothing. Report the answer up to two decimal places. Do not round-up or round-down (for example $0.37914$ is reported as $0.37$). Note: for feature vector $(1,1)$ in class 2 there are fifty points.
What is the value of $w_{11}$?

Type your answer on the interactive page.

Question Q28 SA · 1.5 marks

Consider a binary classification problem. The training-data has several features out of which we have access to only two binary features $(x_1,x_2)$. The labels are $1$ and $2$ for the two classes. The training dataset has the following distribution of points:
FeatureNumber of pointsTrue label
(0,0)301
(0,0)102
(0,1)101
(0,1)402
(1,0)301
(1,0)102
(1,1)101
(1,1)502
The first row states that there are $30$ points from class $1$ with $x_1=0,x_2=0$. A Bernoulli Naive Bayes model is fit with the matrix of probabilities $\begin{bmatrix}w_{11}&w_{12}\\w_{21}&w_{22}\end{bmatrix}$, where $w_{ij}=P(x_i=1\mid y=j)$. You can ignore smoothing. Report the answer up to two decimal places. Do not round-up or round-down (for example $0.37914$ is reported as $0.37$). Note: for feature vector $(1,1)$ in class 2 there are fifty points.
What is the value of $w_{12}$?

Type your answer on the interactive page.

Question Q29 SA · 1.5 marks

Consider a binary classification problem. The training-data has several features out of which we have access to only two binary features $(x_1,x_2)$. The labels are $1$ and $2$ for the two classes. The training dataset has the following distribution of points:
FeatureNumber of pointsTrue label
(0,0)301
(0,0)102
(0,1)101
(0,1)402
(1,0)301
(1,0)102
(1,1)101
(1,1)502
The first row states that there are $30$ points from class $1$ with $x_1=0,x_2=0$. A Bernoulli Naive Bayes model is fit with the matrix of probabilities $\begin{bmatrix}w_{11}&w_{12}\\w_{21}&w_{22}\end{bmatrix}$, where $w_{ij}=P(x_i=1\mid y=j)$. You can ignore smoothing. Report the answer up to two decimal places. Do not round-up or round-down (for example $0.37914$ is reported as $0.37$). Note: for feature vector $(1,1)$ in class 2 there are fifty points.
What is the value of $w_{21}$?

Type your answer on the interactive page.

Question Q30 SA · 1.5 marks

Consider a binary classification problem. The training-data has several features out of which we have access to only two binary features $(x_1,x_2)$. The labels are $1$ and $2$ for the two classes. The training dataset has the following distribution of points:
FeatureNumber of pointsTrue label
(0,0)301
(0,0)102
(0,1)101
(0,1)402
(1,0)301
(1,0)102
(1,1)101
(1,1)502
The first row states that there are $30$ points from class $1$ with $x_1=0,x_2=0$. A Bernoulli Naive Bayes model is fit with the matrix of probabilities $\begin{bmatrix}w_{11}&w_{12}\\w_{21}&w_{22}\end{bmatrix}$, where $w_{ij}=P(x_i=1\mid y=j)$. You can ignore smoothing. Report the answer up to two decimal places. Do not round-up or round-down (for example $0.37914$ is reported as $0.37$). Note: for feature vector $(1,1)$ in class 2 there are fifty points.
What is the value of $w_{22}$?

Type your answer on the interactive page.

Check your answers →

Weeks covering this topic

Other MLT topics