Spam messages have become a major problem in today's digital world, often leading to scams, phishing attacks, and unnecessary clutter in our inboxes. To tackle this issue, I built a machine learning-based spam detection model that can classify emails and SMS messages as spam or not using Natural Language Processing (NLP).
For this project, I used TF-IDF vectorization to extract important features from the text and trained a Multinomial Naive Bayes (MultinomialNB) classifier, which is well-suited for text classification tasks. After testing different techniques, I found that TF-IDF significantly improved performance compared to CountVectorizer.
Since marking a legitimate message as spam (false positive) can have serious consequences*, I focused on optimizing the precision score to reduce such errors and ensure more accurate filtering.
- Dataset: SMS/Email spam dataset sourced from Kaggle here
- Feature Engineering: I have exracted lexical features from the text data.TF-IDF Vectorizer for text transformation
- Machine Learning Model: Multinomial Naive Bayes (with other models explored)
- Evaluation Metric: Precision-focused approach to reduce false positives
You can view below images that I directly copy from the notebook:
- Clone the repository:
git clone https://github.com/bijaypokhrel05/Email-SMS-Spam-Detection.git cd spam-detection-nlp - Install dependencies:
pip install -r requirements.txt
- Run jupyter notebook for training/testing:
jupyter notebook
- Run the app for real-time prediction:
streamlit run app.py
This project demonstrates how Natural Language Processing (NLP) and Machine Learning can effectively classify spam messages. MultinomialNB with TF-IDF proves to be a strong combination for this task. Future improvements could include deep learning-based approaches like LSTMs or transformers for more advanced detection.
