Build Naive Bayes spam classifier with F1
DisneyMachine Learning Engineer · Technical ScreenLast updated
This question evaluates understanding of probabilistic text classification with Naive Bayes, text preprocessing and feature extraction, and use of the F1 score for performance measurement in a binary spam detection task.
You are given a text classification dataset for spam detection (binary labels: spam vs not_spam) in a Jupyter notebook environment.
Task
- Preprocess the text (basic cleaning/tokenization is sufficient).
- Convert text to features suitable for Naive Bayes (e.g., bag-of-words or TF-IDF).
- Train a Naive Bayes classifier.
- Evaluate the model using F1 score (clearly state whether it is the F1 for the positive class or a specific averaging scheme).
- Run the trained model on a few test examples and show predicted labels (and optionally probabilities).
Constraints / Notes
- The dataset may be class-imbalanced.
- You should avoid data leakage (fit text vectorizer only on training data).
- You may choose reasonable train/validation splitting if only one labeled set is provided.
Solution walkthrough is for members
Get the full walkthrough with reference code and complexity analysis, plus Kitty Coach at 300 messages a day. Hints, the code runner and community answers stay free.