0
0
ML Pythonprogramming~20 mins

Naive Bayes classifier in ML Python - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Naive Bayes Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
1:30remaining
How does Naive Bayes handle feature independence?

Naive Bayes assumes that features are independent given the class. What does this mean in simple terms?

AFeatures depend on each other to predict the class.
BFeatures are combined into one before classification.
CFeatures are ignored if they are correlated.
DEach feature affects the class independently without influencing other features.
Attempts:
2 left
Predict Output
intermediate
2:00remaining
Output of Naive Bayes prediction code

What is the predicted class output by this code snippet?

ML Python
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])
A0
B1
C2
DError
Attempts:
2 left
Hyperparameter
advanced
1:30remaining
Choosing the smoothing parameter in Naive Bayes

In Multinomial Naive Bayes, what effect does increasing the smoothing parameter alpha have on the model?

AIt removes features with low frequency from the dataset.
BIt reduces the effect of zero-frequency problems by adding more weight to unseen features.
CIt decreases training time by skipping some features.
DIt increases the model complexity by adding more features.
Attempts:
2 left
Metrics
advanced
1:30remaining
Evaluating Naive Bayes with imbalanced data

You trained a Naive Bayes classifier on imbalanced classes. Which metric is best to evaluate its performance fairly?

AF1-score
BAccuracy
CPrecision
DTraining loss
Attempts:
2 left
🔧 Debug
expert
2:00remaining
Why does this Naive Bayes code raise an error?

What error does this code raise and why?

ML Python
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)
AIndexError: list index out of range
BTypeError: Unsupported operand type(s) for +: 'int' and 'str'
CValueError: Found input variables with inconsistent numbers of samples
DNo error, code runs successfully
Attempts:
2 left