This project implements a machine learning-based spam detection system that classifies SMS messages as either "spam" or "ham" (legitimate) using the Multinomial Naïve Bayes algorithm with TF-IDF feature extraction.
- Text Preprocessing: Comprehensive text cleaning including lowercasing, punctuation removal, tokenization, stopword removal, and lemmatization
- TF-IDF Vectorization: Converts text into numerical features using Term Frequency-Inverse Document Frequency with bigram support
- Multinomial Naïve Bayes: Probabilistic classifier optimized for text classification tasks
- Performance Metrics: Detailed evaluation including accuracy, precision, recall, F1-score, and confusion matrix
- Feature Importance Analysis: Identifies top spam and ham indicator words
- Custom Prediction Function: Easy-to-use interface for classifying new messages
SMS Spam Collection Dataset
(https://www.kaggle.com/datasets/uciml/sms-spam-collection-dataset)
- Text messages labeled as spam or ham
- Imbalanced dataset with more legitimate messages than spam
- Preprocessed and cleaned for optimal model performance
- pandas - Data manipulation and analysis
- numpy - Numerical computing
- matplotlib & seaborn - Data visualization
- nltk - Natural language processing
- scikit-learn - Machine learning algorithms and utilities
- TfidfVectorizer
- MultinomialNB
- train_test_split
- Performance metrics
.
├── ML_Project_Spam_SMS_Classifier.ipynb # Main notebook
├── SMSSpamCollection # Dataset file
└── README.md # Project documentation
- Ensure the
SMSSpamCollectiondataset is in the same directory - Open
ML_Project_Spam_SMS_Classifier.ipynbin Jupyter Notebook - Run all cells sequentially