Spam message classifier
Classify SMS or emails as spam or not using TF-IDF and Naive Bayes, with attention to precision and recall.
Beginnerâą 6â8 hoursđĒ 7 stepsPythonscikit-learnNLP basics
What you'll learn
- âText vectorisation with TF-IDF
- âNaive Bayes and logistic regression
- âPrecision, recall and the confusion matrix
What you'll build
- âCleans text
- âTwo models compared
- âConfusion matrix and classification report
- âTry-it box for any message
Step-by-step guide
- 1
Dataset
The UCI "SMS Spam Collection" dataset (about 5,500 labelled messages).
- 2
Look at the balance
Only ~13% are spam, so accuracy alone is misleading; plan to use precision and recall.
- 3
Vectorise
TfidfVectorizer(lowercase=True, stop_words="english", ngram_range=(1, 2)) inside a Pipeline.
- 4
Train
MultinomialNB and LogisticRegression(class_weight="balanced"); stratified train/test split.
- 5
Evaluate
classification_report and ConfusionMatrixDisplay; discuss which error is worse (real message in spam folder).
- 6
Threshold
Use predict_proba and pick a threshold that keeps precision for spam above 98%.
- 7
Demo
A Streamlit text box that shows the prediction and probability.
đ Make it stand out
- +Explain predictions with top weighted words
- +Try a small transformer model
- +Hindi/Hinglish messages