Katkat

Build Naive Bayes spam classifier with F1

DisneyMachine Learning Engineer · Technical Screen

Last 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

  1. Preprocess the text (basic cleaning/tokenization is sufficient).
  2. Convert text to features suitable for Naive Bayes (e.g., bag-of-words or TF-IDF).
  3. Train a Naive Bayes classifier.
  4. Evaluate the model using F1 score (clearly state whether it is the F1 for the positive class or a specific averaging scheme).
  5. 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.