Naive Bayes assumes that features are independent given the class. What does this mean in simple terms?
Think about how Naive Bayes simplifies calculations by treating features separately.
Naive Bayes assumes each feature contributes independently to the probability of the class. This simplifies the math and makes the model fast.
What is the predicted class output by this code snippet?
from sklearn.naive_bayes import GaussianNB import numpy as np X_train = np.array([[1, 20], [2, 21], [3, 22], [4, 23]]) y_train = np.array([0, 0, 1, 1]) model = GaussianNB() model.fit(X_train, y_train) X_test = np.array([[1.5, 20.5]]) prediction = model.predict(X_test) print(prediction[0])
Look at the training data and which class is closer to the test point.
The test point [1.5, 20.5] is closer to the points labeled 0, so the model predicts class 0.
In Multinomial Naive Bayes, what effect does increasing the smoothing parameter alpha have on the model?
Think about how smoothing helps when a feature never appears in training for a class.
Smoothing adds a small value to feature counts to avoid zero probabilities, helping the model handle unseen features better.
You trained a Naive Bayes classifier on imbalanced classes. Which metric is best to evaluate its performance fairly?
Accuracy can be misleading when one class dominates.
F1-score balances precision and recall, giving a better sense of performance on imbalanced data.
What error does this code raise and why?
from sklearn.naive_bayes import GaussianNB X_train = [[1, 2], [3, 4]] y_train = [0, 1, 0] model = GaussianNB() model.fit(X_train, y_train)
Check if the number of samples in features and labels match.
The feature list has 2 samples but the label list has 3, causing a mismatch error.
