Binary classification
Classify messages as ham (0), meaning legitimate, or spam (1), meaning unwanted.
SMS Spam Detection is a binary text classification project that distinguishes unwanted messages from legitimate SMS using Bag-of-Words features and Multinomial Naive Bayes. An exploratory notebook was reorganized into a reusable training, evaluation, and inference pipeline.

Text messages are short, noisy, and often contain promotional language. The goal was to build a lightweight classifier that learns recurring patterns without requiring a large neural network.
Classify messages as ham (0), meaning legitimate, or spam (1), meaning unwanted.
Transform raw SMS text into sparse numerical counts that a machine learning algorithm can learn from.
Measure spam precision, recall, and F1-score in addition to overall accuracy because the dataset is imbalanced.
The original experiment uses 5,572 labeled messages: 4,825 ham and 747 spam. Dataset files are not redistributed with the repository.
A compact pipeline connects data preparation, sparse vectorization, classification, and held-out evaluation. Its fitted vocabulary is reused during inference.
Labeled English text, ham or spam
80% training · 20% evaluation
Convert messages into sparse word-count vectors
Learn class probabilities from word counts
Predict labels and evaluate performance
The refactored implementation fits feature extraction on training data only, helping prevent data leakage.
Rather than increasing model complexity, this project demonstrates a well-defined baseline with reusable scripts and a consistent preprocessing-to-prediction workflow.
CountVectorizer represents each message through token counts, producing a sparse feature matrix.
A fast probabilistic classifier suitable for count-based text features and baseline comparison.
The reorganized code uses a stratified 80/20 split with random_state=42 for repeatable experiments.
Training produces a serialized pipeline containing the vectorizer and classifier for consistent inference.
Evaluation outputs a classification report and a confusion matrix, with particular attention to spam errors.
Small tests validate data handling and the pipeline using synthetic examples without requiring the original CSV.
The original notebook reported high performance on a held-out set. The refactored scripts define a repeatable experiment, but their metrics must be measured separately.
| Metric | Reported value |
|---|---|
| Overall accuracy | ~99% |
| Spam precision | 0.98 |
| Spam recall | 0.93 |
| Spam F1-score | 0.95 |
| Test messages | 1,115 |
Historical results from the uploaded notebook; its random split had no fixed seed. These are not verified results of a fresh training run.
The ham class is much more frequent than spam. Precision helps understand how often spam predictions are correct, while recall measures how much actual spam is detected.
A visual illustration of how multiple incoming messages can be classified and displayed together. The published repository includes a command-line inference script rather than a web application.

The exploratory work was organized into Python modules, a lightweight testing layer, and practical commands to train a model or classify new text.
spam-detection-nlp/
├── data/raw/
├── notebooks/
├── src/
│ ├── data.py
│ ├── model.py
│ ├── train.py
│ └── predict.py
├── tests/
├── models/
├── reports/
└── README.mdpython -m src.trainpython -m src.predict "Free prize!"pytest -qDownload spam.csv from Kaggle and save it to data/raw/ before training.
Read the project README, inspect the model pipeline, or run the tests locally.
The value of this project is not just its accuracy: it taught me how to translate a small exploratory ML experiment into a testable workflow and how to assess a classifier responsibly.
A good baseline is useful when its assumptions are visible. This project connected text representation, probability-based learning, imbalanced data evaluation, and reproducible software organization.
I learned how word-frequency representations turn unstructured messages into sparse features suitable for classical machine learning.
Multinomial Naive Bayes showed me the value of computationally inexpensive baselines before moving to more complex architectures.
I learned why precision, recall, F1-score, and false positives can be more informative than overall accuracy for the spam class.
Restructuring the notebook helped me separate data loading, training, evaluation, and inference while reducing data leakage risk.
Even a small text classifier benefits from careful splitting, transparent metrics, consistent inference and reusable code.
This project demonstrates a classical NLP technique on a fixed English SMS dataset. Results may not transfer directly to modern scams, email, other languages, or adversarial messages.
Word counts ignore much of the context and word order. The dataset represents a limited distribution, while spam patterns evolve over time.
The image is for portfolio presentation. The shared code is a trainable, testable ML baseline; it is not a live SMS or email security service.