A spam classifier, compared three ways
The problem
Build a spam filter for short messages with three different methods and decide which one you would deploy, with evidence.
Requirements
- Write or collect at least 60 short messages labelled spam or ham, and hold out a test set
- Implement Naive Bayes with Laplace smoothing and log probabilities
- Implement logistic regression on word-count features and k-NN on the same features
- Report the confusion matrix, precision, recall and F1 for each method
- Choose a decision threshold for logistic regression that suits the cost of losing a real message
Technologies
- Python
- Naive Bayes
- Logistic regression
- k-NN
- Classification metrics
Step by step
- Collect and label the messages; split them into training, validation and test sets.
- Turn each message into word counts over a vocabulary built from the training set.
- Train the three classifiers and compare them on the validation set.
- Pick a threshold and a winner, then evaluate once on the test set.
- Write a short recommendation explaining the trade-off you chose.
Expected result
Three working classifiers, a table of their scores, and a reasoned choice of the one to deploy.
How it is evaluated
- All three methods beat the majority-class baseline
- Metrics are computed correctly and shown for each method
- The threshold choice is justified by the costs of each mistake
- The vocabulary and every statistic come from training data only
Ways to improve it
- Add a decision tree or a random forest and compare
- Use word pairs (bigrams) as extra features
- Check results separately for long and short messages