>_ Jorge Uc / projects ← All projects
~/projects/spam-detection // NLP + MACHINE LEARNING
◆ Text classificationPython + scikit-learnReproducible baseline

Filtering noise.
Finding signal.

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.

Laptop displaying SMS spam classification results
PROJECT FILE / NLP-001SPAM / HAM
DATASET5,572English SMS messages
ORIGINAL ACCURACY~99%Historical notebook run
SPAM F10.95Historical notebook run
CLASSIFIERNBMultinomial Naive Bayes
01 / PROJECT CONTEXT

Can a simple model recognize spam?

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.

01TASK

Binary classification

Classify messages as ham (0), meaning legitimate, or spam (1), meaning unwanted.

SUPERVISED LEARNING
02FEATURES

Turn words into data

Transform raw SMS text into sparse numerical counts that a machine learning algorithm can learn from.

NLP / BAG-OF-WORDS
03EVALUATION

Look beyond accuracy

Measure spam precision, recall, and F1-score in addition to overall accuracy because the dataset is imbalanced.

MODEL ASSESSMENT
DATA SOURCE

SMS Spam Collection · Kaggle mirror

The original experiment uses 5,572 labeled messages: 4,825 ham and 747 spam. Dataset files are not redistributed with the repository.

Dataset on Kaggle ↗
02 / NLP PIPELINE

From SMS text to a predicted label.

A compact pipeline connects data preparation, sparse vectorization, classification, and held-out evaluation. Its fitted vocabulary is reused during inference.

> pipeline.fit(X_train, y_train)CONCEPTUAL FLOW
01 / INPUT

SMS messages

Labeled English text, ham or spam

02 / SPLIT

Train / test

80% training · 20% evaluation

03 / FEATURES

CountVectorizer

Convert messages into sparse word-count vectors

04 / MODEL

MultinomialNB

Learn class probabilities from word counts

05 / OUTPUT

HAM / SPAM

Predict labels and evaluate performance

The refactored implementation fits feature extraction on training data only, helping prevent data leakage.

03 / IMPLEMENTATION

Classical NLP, practical engineering.

Rather than increasing model complexity, this project demonstrates a well-defined baseline with reusable scripts and a consistent preprocessing-to-prediction workflow.

01 / REPRESENTATION

Bag-of-Words

CountVectorizer represents each message through token counts, producing a sparse feature matrix.

02 / CLASSIFICATION

Multinomial Naive Bayes

A fast probabilistic classifier suitable for count-based text features and baseline comparison.

03 / REPRODUCIBILITY

Fixed train/test split

The reorganized code uses a stratified 80/20 split with random_state=42 for repeatable experiments.

04 / ARTIFACTS

Saved ML pipeline

Training produces a serialized pipeline containing the vectorizer and classifier for consistent inference.

05 / EVALUATION

Classification metrics

Evaluation outputs a classification report and a confusion matrix, with particular attention to spam errors.

06 / QUALITY

Automated tests

Small tests validate data handling and the pipeline using synthetic examples without requiring the original CSV.

04 / HISTORICAL EVALUATION

Strong baseline, carefully interpreted.

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.

ORIGINAL NOTEBOOK RESULTS
MetricReported value
Overall accuracy~99%
Spam precision0.98
Spam recall0.93
Spam F1-score0.95
Test messages1,115

Historical results from the uploaded notebook; its random split had no fixed seed. These are not verified results of a fresh training run.

WHY IT MATTERSAccuracy alone can hide missed spam.

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.

HAM4,825 · 86.6%
SPAM747 · 13.4%
05 / PROJECT SHOWCASE

Batch predictions at a glance.

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.

Illustrative laptop mockup showing a table of classified SMS messages
Portfolio illustration of batch classification · The screenshot is a presentation mockup, not evidence of a deployed application.
06 / REPRODUCIBILITY

More than a single notebook.

The exploratory work was organized into Python modules, a lightweight testing layer, and practical commands to train a model or classify new text.

PROJECT STRUCTURE
spam-detection-nlp/
├── data/raw/
├── notebooks/
├── src/
│   ├── data.py
│   ├── model.py
│   ├── train.py
│   └── predict.py
├── tests/
├── models/
├── reports/
└── README.md
RUN LOCALLY

Train the model

python -m src.train

Predict a message

python -m src.predict "Free prize!"

Run tests

pytest -q

Download spam.csv from Kaggle and save it to data/raw/ before training.

SOURCE CODE

Explore the reproducible implementation.

Read the project README, inspect the model pipeline, or run the tests locally.

Explore on GitHub ↗
07 / PERSONAL RETROSPECTIVE

What I learned building this classifier.

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.

BEYOND THE METRIC

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.

01 / FEATURE ENGINEERING

Text needs a numerical representation

I learned how word-frequency representations turn unstructured messages into sparse features suitable for classical machine learning.

NLPCountVectorizerSparse data
02 / PROBABILISTIC LEARNING

Simple models can be effective

Multinomial Naive Bayes showed me the value of computationally inexpensive baselines before moving to more complex architectures.

Naive BayesClassificationBaselines
03 / EVALUATION

Class imbalance changes the story

I learned why precision, recall, F1-score, and false positives can be more informative than overall accuracy for the spam class.

PrecisionRecallF1-score
04 / ML ENGINEERING

Experiments should be repeatable

Restructuring the notebook helped me separate data loading, training, evaluation, and inference while reducing data leakage risk.

Python modulesTestingReproducibility
KEY TAKEAWAY

Reliable ML starts with clear experiments, not just advanced models.

Even a small text classifier benefits from careful splitting, transparent metrics, consistent inference and reusable code.

08 / LIMITATIONS & SCOPE

A useful baseline, not a production filter.

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.

KNOWN LIMITATIONS

Short-text domain and drift

Word counts ignore much of the context and word order. The dataset represents a limited distribution, while spam patterns evolve over time.

RESPONSIBLE INTERPRETATION

No deployed spam defense

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.