An end-to-end NLP pipeline that automatically flags spam in SMS messages using classical machine-learning models.
-
Data
- Source: SMS Spam Collection v1
- Format:
label\tmessage(ham/spam)
-
Preprocessing
- Strip URLs, emails, numbers, punctuation
- Expand contractions, lowercase
- Tokenize, remove stop-words, lemmatize
-
Feature Extraction
- TF-IDF vectors (unigrams & bigrams)
-
Modeling & Tuning
- Train/test split (80/20)
- Compare 7 classifiers:
- Multinomial Naïve Bayes
- Logistic Regression
- Decision Tree
- Random Forest
- Gradient Boosting
- Support Vector Machine
- k-Nearest Neighbors
- Select best by accuracy
-
Evaluation
- Confusion matrix
- Accuracy summary
-
Usage
import joblib model = joblib.load("models/best_model.pkl") print(model.predict([ "Free entry in 2 a wkly comp to win FA Cup finals!", "Are we still meeting at 6pm?" ])) # ['spam', 'ham']