A machine learning project that classifies SMS messages as spam or ham (not spam) using Natural Language Processing (NLP) techniques.
This project implements and compares two commonly used models for text classification: Logistic Regression and Multinomial Naive Bayes, allowing for a practical understanding of how different algorithms perform on word-based data.
- Text vectorisation using:
- TF-IDF
- Count Vectorizer
- Machine learning models:
- Logistic Regression
- Multinomial Naive Bayes
- End-to-end ML pipelines (vectorisation + model)
- Hyperparameter tuning using GridSearchCV
- Model evaluation using:
- Accuracy
- Precision
- Recall
- F1 Score
- Confusion matrix visualisation
- Interactive user input for real-time message classification
- Load and clean dataset
- Remove duplicate messages
- Split data into training and testing sets
- Build pipelines (vectorisation + model)
- Train models using GridSearchCV
- Tune hyperparameters
- Evaluate model performance on unseen data
- Compare model results
- Classify custom user input messages
This project uses a labelled dataset of SMS messages:
- Spam → unwanted / promotional messages
- Ham → normal messages
File: spamhamdata.csv
- Python
- pandas
- NumPy
- scikit-learn
- matplotlib
The model outputs:
- Accuracy
- Precision
- Recall
- F1 Score
A confusion matrix is also generated for visual performance analysis.
-
Install dependencies: pip install -r requirements.txt
-
Run the program:
-
Choose a model:
l→ Logistic Regressionn→ Naive Bayes
- Optionally view evaluation results
This project was built to:
- understand the machine learning pipeline
- work with text data
- compare different ML models
- practise hyperparameter tuning