A powerful and accurate Machine Learning-based solution that detects whether a given SMS or email is spam or not. This project uses Logistic Regression and TF-IDF vectorization, built using Python, Scikit-learn, Pandas, and Streamlit.
Spam-SMS-Email-Classifier/
│
├── data/
│ └── spam.csv # Raw dataset (SMS labeled as ham/spam)
│
├── pkl/
│ ├── model.pkl # Trained ML model (Logistic Regression)
│ └── vectorizer.pkl # TF-IDF vectorizer
│
├── app.py # Streamlit app for message prediction
├── spam_classifier_notebook.ipynb # Jupyter notebook with full model pipeline
├── README.md # Project documentation
├── requirements.txt # Python dependencies
└── .gitignore
- Detects whether input message is Spam or Not
- Uses Logistic Regression (option to change model)
- Data preprocessing & text cleaning
- Spam class balancing using upsampling
- TF-IDF feature extraction (top 5000 features)
- User-friendly Streamlit Web App
- Ready for deployment (Render/HuggingFace)
- Dataset:
spam.csv - Classes:
ham: Legitimate messagesspam: Fraud, loan, prize messages
git clone https://github.com/DevWaqarAhmad/Spam-SMS-Email-Classifier.git
cd Spam-SMS-Email-Classifierpython -m venv env- On Windows:
env\Scripts\activatepip install -r requirements.txtstreamlit run app.py- Vectorizer:
TfidfVectorizerwithmax_features=5000 - Classifier:
LogisticRegression (max_iter=1000) - Balanced Dataset: Using
sklearn.utils.resampleto upsample spam class - Accuracy Achieved: ~97-98%
| Message | Prediction |
|---|---|
| "Claim your free $5000 loan now. No documents required!" | Spam |
| "Hey, meeting is at 3 PM today. Don't be late." | Not Spam |
| ✅ Not Spam Example | 🚫 Spam Example |
|---|---|
![]() |
![]() |
These screenshots show how the Streamlit app classifies input text messages.
Deployed app link will be added here once hosted on Render/HuggingFace
Waqar Ahmad
📧 Email: devwaqarahmad@gmail.com
🌐 GitHub: DevWaqarAhmad
This project is licensed under the MIT License.
Pull requests are welcome! For major changes, please open an issue first to discuss what you would like to change.

