A machine learning project to classify email and SMS messages as spam or not spam using Natural Language Processing (NLP) techniques and various classification algorithms. The project includes a Streamlit web app for easy interaction.
This project aims to classify messages as spam or not spam using machine learning techniques. The model is built and evaluated using various metrics, and a Streamlit web application is developed for user interaction.
The dataset used for this project is the SMS Spam Collection Dataset, which is available at UCI Machine Learning Repository. Link: https://archive.ics.uci.edu/dataset/228/sms+spam+collection
- Clone the repository:
git clone https://github.com/rahulkumarmmmut/sms-spam-classifier.git
cd sms-spam-classifier
- Create a virtual environment and activate it:
python -m venv env
source env/bin/activate # On Windows use `env\Scripts\activate`
- Install the required packages:
pip install -r requirements.txt
- Download NLTK data:
import nltk
nltk.download('punkt')
nltk.download('stopwords')
- Dropped unnecessary columns.
- Renamed columns for clarity.
- Encoded target labels.
- Removed duplicate entries.
- Visualized the distribution of spam and ham messages.
- Analyzed message length, word count, and sentence count.
- Created histograms and pair plots for deeper insights.
- Converted text to lowercase.
- Tokenized the text.
- Removed special characters, stop words, and punctuation.
- Applied stemming to reduce words to their root form.
- Used CountVectorizer and TfidfVectorizer for text vectorization.
- Scaled the features using MinMaxScaler.
- Built models using GaussianNB, MultinomialNB, and BernoulliNB.
- Evaluated models using accuracy, confusion matrix, and precision score.
- Chose the best-performing model for deployment.
Developed a Streamlit web application with the following features:
- Text area for inputting messages.
- Button to trigger prediction.
- Display of the prediction result (Spam or Not Spam).
- Run the Streamlit app:
streamlit run app/app.py
- Open your web browser and go to http://localhost:8501.
- Enter a message in the text area and click the "Predict" button to see the result.
- Improve the model by trying different algorithms and hyperparameter tuning.
- Enhance the web app with more features and a better UI.
- Deploy the app on a cloud platform for wider accessibility.
This project is licensed under the MIT License. See the LICENSE file for details.