A classical NLP machine learning project that classifies messages as spam or ham (legitimate) using TF-IDF vectorisation and Logistic Regression β no deep learning required.
pip install -r requirements.txtUCI SMS Spam Collection:
https://archive.ics.uci.edu/dataset/228/sms+spam+collection
β Download and place `SMSSpamCollection` file in the `data/` folder.
(It's a tab-separated file with no header β no renaming needed.)
python notebooks/eda.pyGenerates distribution plots and top word charts in plots/.
python src/train.pyTrains Naive Bayes and Logistic Regression, prints comparison metrics,
saves best model as model.pkl, and generates evaluation plots.
streamlit run app.pyOpens at http://localhost:8501 β classify any message in real time.
| Metric | Naive Bayes | Logistic Regression |
|---|---|---|
| Accuracy | 97.8% | 98.5% |
| Precision | 95.1% | 97.2% |
| Recall | 92.3% | 94.8% |
Why precision matters: A false positive (real email marked as spam) costs the user an important missed message. We optimise for high precision while keeping recall strong.
##ML Concepts Covered
| Concept | Where Used |
|---|---|
| Text preprocessing (tokenisation, stopwords, stemming) | preprocess_text.py |
| TF-IDF vectorisation with n-grams | train.py β build_vectorizer() |
| Multinomial Naive Bayes | train.py |
| Logistic Regression | train.py |
| Train/test split with stratification | train.py |
| 5-fold cross-validation | train.py |
| Confusion matrix | train.py β _plot_confusion_matrices() |
| ROC curve & AUC | train.py β _plot_roc_curves() |
| Feature importance | train.py β _plot_top_features() |
| sklearn Pipeline | Combines vectoriser + classifier into one object |
| Model persistence (joblib) | train.py β save_model() |
- Demonstrates end-to-end ML pipeline (data β cleaning β training β deployment)
- Real-world NLP use case everyone understands immediately
- Shows knowledge of evaluation metrics beyond accuracy
- Streamlit deployment β live demo-able in any interview
- Feature importance analysis shows understanding of why the model works