0
0
NLPml~20 mins

Naive Bayes for text in NLP - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Naive Bayes Text Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
1:30remaining
How does Naive Bayes handle word independence in text classification?
Naive Bayes assumes that words in a text are independent of each other when calculating probabilities. What does this assumption mean in simple terms?
AWords are grouped into pairs and their combined frequency is used for classification.
BThe order of words in the text is the most important factor for classification.
CEach word's presence or absence does not affect the presence of any other word in the text.
DWords are ignored and only sentence length is used for classification.
Attempts:
2 left
💡 Hint
Think about how the model treats each word when calculating probabilities.
Predict Output
intermediate
2:00remaining
Output of Naive Bayes prediction probabilities
Given the following Python code using sklearn's MultinomialNB for text classification, what is the output of the prediction probabilities?
NLP
from sklearn.feature_extraction.text import CountVectorizer
from sklearn.naive_bayes import MultinomialNB

texts = ['I love apples', 'I hate bananas']
labels = [1, 0]

vectorizer = CountVectorizer()
X = vectorizer.fit_transform(texts)

model = MultinomialNB()
model.fit(X, labels)

new_text = ['I love bananas']
X_new = vectorizer.transform(new_text)
probs = model.predict_proba(X_new)
print(probs)
A[[0.5 0.5]]
B[[0.75 0.25]]
C[[0.25 0.75]]
D[[1.0 0.0]]
Attempts:
2 left
💡 Hint
Look at how the model was trained and the new text features.
Model Choice
advanced
1:30remaining
Choosing the best Naive Bayes variant for text with word counts
You have a dataset of text documents represented as word counts. Which Naive Bayes variant is most suitable for this data?
AMultinomial Naive Bayes
BComplement Naive Bayes
CBernoulli Naive Bayes
DGaussian Naive Bayes
Attempts:
2 left
💡 Hint
Consider which variant models count data well.
Hyperparameter
advanced
1:30remaining
Effect of smoothing parameter alpha in Naive Bayes
In Multinomial Naive Bayes, what is the effect of increasing the smoothing parameter alpha?
AIt removes stop words automatically from the text data.
BIt increases the influence of rare words by adding more weight to zero counts.
CIt decreases the model's ability to handle unseen words by ignoring them.
DIt prevents zero probabilities by adding a small count to all features, smoothing the model.
Attempts:
2 left
💡 Hint
Think about how smoothing helps with words not seen in training.
Metrics
expert
2:00remaining
Interpreting Naive Bayes classification report metrics
A Naive Bayes text classifier reports the following metrics on test data: precision=0.8, recall=0.5, accuracy=0.7. What does this tell you about the model's performance?
AThe model perfectly balances false positives and false negatives.
BThe model is good at finding positive examples but misses many actual positives.
CThe model predicts positives too often, causing many false positives.
DThe model has high recall but low precision.
Attempts:
2 left
💡 Hint
Recall measures how many actual positives are found, precision measures correctness of positive predictions.