Built to order

SMS Spam Detection using NLP (UCI SMS Spam Collection)

This project builds an SMS spam filter that learns the language of spam from 5,574 real labelled text messages. A TF-IDF + Multinomial Naive Bayes pipeline is trained on the UCI SMS Spam Collection, evaluated with precision, recall and a confusion matrix, and served through a web demo that classifies any pasted SMS and shows exactly which words drove the decision. Data cleaning, vectorisation, model choice and metrics are all documented for a confident viva. Suitable for B.E./B.Tech final-year projects in Computer Science, IT and AI & Machine Learning.

Chat on WhatsApp — get a quotation

AI & Machine Learning scikit-learnJupyter notebookNLTKPython 3pandas · NumPyHTML · CSS · JS demoTF-IDF · Naive BayesUCI SMS Spam CollectionSoftware
SMS Spam Detection using NLP (UCI SMS Spam Collection) — project thumbnail preview
More project photos (3)

The problem

SMS spam is still one of the most effective fraud channels: prize scams, fake job offers and phishing links arrive as plain text on the one device everybody reads. Rule-based blockers collapse the moment spammers rephrase a message, which is why the industry moved to learning-based filters that score the language itself. This project builds that filter properly — a TF-IDF + Multinomial Naive Bayes classifier trained on the UCI SMS Spam Collection, the standard public benchmark of 5,574 real hand-labelled messages. Because the dataset is genuinely imbalanced (only 13.4% spam), the project teaches the parts students usually skip: stratified splits, class-weighted training, and why precision/recall matter more than accuracy on skewed data. A live web demo makes the model tangible: paste any SMS and see the verdict, the spam probability, and the exact tokens that pushed the decision.

SYSTEM FLOW

4 components 5 connections

Live flow
Drag to explore
100%
userUser

Pastes an SMS into the web demo to check for spam.

Follow the working sequence

How it works

  1. The 5,574 messages of the UCI SMS Spam Collection are loaded and labelled ham (4,827) or spam (747).
  2. Text is normalised: lowercasing, URL/number masking, tokenisation, and removal of 153 English stop-words.
  3. Messages are vectorised with TF-IDF over word unigrams and bigrams (8,000-term vocabulary).
  4. Data is split 80/10/10 with stratification so every split keeps the 13.4% spam rate.
  5. Multinomial Naive Bayes (plus a Logistic Regression baseline) is trained with class-weighted loss on the training split and tuned on validation.
  6. The test split is evaluated once: accuracy, per-class precision/recall/F1 and the confusion matrix go into the report.
  7. In the web demo, a pasted SMS passes through the identical preprocessing and the fitted pipeline returns the verdict, probability and contributing tokens.

Tech stack:

  • Python 3, scikit-learn
  • pandas, NumPy
  • NLTK (tokenisation, stop-words)
  • Jupyter Notebook (training & evaluation)
  • Matplotlib, Seaborn (plots)
  • HTML, CSS, JavaScript (classifier web demo)
  • UCI SMS Spam Collection (dataset)

Dataset & model details

  • Dataset: UCI SMS Spam Collection (Almeida & Hidalgo, UCI ML Repository, 2011) — 5,574 real English SMS messages, hand-labelled: 4,827 ham (86.6%) and 747 spam (13.4%). Sourced from forums, the NUS SMS corpus and the SMS Spam Corpus.
  • Task: Binary text classification; input = raw SMS text, output = ham/spam label plus spam probability.
  • Model: Primary: TF-IDF (word unigrams + bigrams, 8,000-term vocabulary) → Multinomial Naive Bayes with class-weighted priors. Baseline for comparison: Logistic Regression on the same vectors.
  • Metrics: Test accuracy ≈ 98% (design target for the built-to-order training run), spam-class precision/recall/F1, confusion matrix. No accuracy is claimed as measured until the training run is executed for the order.
Parameter Value
Input format Raw SMS text, any length (expected)
Messages 5,574 labelled (4,827 ham / 747 spam)
Classes 2 (ham, spam)
Vocabulary 8,000 TF-IDF terms, uni + bigrams (design target)
Test accuracy ≈ 98% (design target, not a measured claim)
Spam-class F1 ≈ 0.97 (design target)
Inference < 5 ms per message on CPU (expected)
Split 80 / 10 / 10 stratified train/val/test
Model file Fitted pipeline, a few MB (expected)
Demo Single-file web app, runs offline after download

Project features

  • [TF-IDF + Multinomial Naive Bayes pipeline] Word unigram + bigram TF-IDF vectors (8k vocabulary) feeding a Multinomial Naive Bayes classifier — the classic, fast and naturally probabilistic text-classification stack, tuned end to end.
  • [Live SMS classifier web demo] Paste any message and get an instant ham/spam verdict with a spam-probability score, running the same preprocessing the trained model uses.
  • [Token-level explanations] Every prediction lists the top contributing tokens with their log-probability weights, so the decision is transparent instead of a black box — a strong viva talking point.
  • [Full training notebook] Data loading, cleaning, vectorisation, stratified splitting, model fitting and evaluation in one reproducible Jupyter notebook.
  • [Confusion matrix & per-class report] Precision, recall and F1 for both classes on the held-out test split, with an honest discussion of the false positives and false negatives.
  • [Logistic Regression baseline] A second model trained alongside for comparison, so the report can justify the final model choice with numbers instead of assertions.
  • [Stratified 80/10/10 evaluation] Train/validation/test splits that preserve the 13.4% spam rate, with the test set touched exactly once.

What is included

  • Complete training & evaluation Jupyter notebook
  • Fitted TF-IDF + Naive Bayes pipeline (and Logistic Regression baseline) with preprocessing code
  • Live SMS classifier web demo with token-level explanations
  • Confusion matrix, per-class metrics and training plots
  • Project report PDF (background, NLP theory, methodology, results)
  • PPT presentation for final review
  • Viva Q&A preparation document (TF-IDF, Naive Bayes, precision/recall, class imbalance)

Limitations & prerequisites

  • English SMS only — code-mixed (Hinglish) or transliterated text is out of scope.
  • Adversarial obfuscation such as "fr33" or "w1nner" degrades token matching.
  • Very short messages (under ~4 tokens) carry little signal and default toward ham.
  • Spam tactics drift over time — the model needs periodic retraining on fresh data.
  • 98% accuracy is a design target for the training run, stated honestly — the report documents the actual achieved figure after training.
  • The browser demo mirrors the fitted pipeline's behaviour; it is a teaching interface, not a production filter.

Frequently Asked Questions

Which dataset is used and why?

The UCI SMS Spam Collection — 5,574 real, hand-labelled SMS messages. It is the standard benchmark for this task, small enough to train in seconds on a laptop, and its realistic 6.5:1 class imbalance teaches proper evaluation on skewed data.

Why Naive Bayes instead of deep learning?

For short-text classification with sparse TF-IDF features, Multinomial Naive Bayes is fast, naturally probabilistic and hard to beat without far more data. The notebook also trains a Logistic Regression baseline so the choice is justified empirically.

How does the demo explain its decisions?

Every prediction shows the top contributing tokens with their log-probability weights (e.g. "prize +2.10", "claim +1.75"), so you can see exactly which words pushed the message toward spam or ham.

Can it catch spam it has never seen?

It generalises to new phrasings that reuse spam-like vocabulary, but genuinely novel scam templates and deliberate obfuscation are its weak points — discussed honestly in the report's limitations.

Does it work on WhatsApp or email spam?

As shipped it is trained on SMS-length English text. The same pipeline retrains on other short-text sources, listed as future scope with the steps involved.

Is this project suitable for a final-year project?

Yes — for Computer Science, IT and AI/ML programs. It demonstrates NLP preprocessing, feature engineering, probabilistic modelling and honest evaluation on imbalanced data. Suitable for B.E./B.Tech final-year projects in Computer Science, IT and AI & Machine Learning.

Components & software requirements
  • Python 3, scikit-learn
  • pandas, NumPy
  • NLTK (tokenisation, stop-words)
  • Jupyter Notebook (training & evaluation)
  • Matplotlib, Seaborn (plots)
  • HTML, CSS, JavaScript (classifier web demo)
  • UCI SMS Spam Collection (dataset)

Dataset & model details

  • Dataset: UCI SMS Spam Collection (Almeida & Hidalgo, UCI ML Repository, 2011) — 5,574 real English SMS messages, hand-labelled: 4,827 ham (86.6%) and 747 spam (13.4%). Sourced from forums, the NUS SMS corpus and the SMS Spam Corpus.
  • Task: Binary text classification; input = raw SMS text, output = ham/spam label plus spam probability.
  • Model: Primary: TF-IDF (word unigrams + bigrams, 8,000-term vocabulary) → Multinomial Naive Bayes with class-weighted priors. Baseline for comparison: Logistic Regression on the same vectors.
  • Metrics: Test accuracy ≈ 98% (design target for the built-to-order training run), spam-class precision/recall/F1, confusion matrix. No accuracy is claimed as measured until the training run is executed for the order.
Delivery information

Built-to-order project. Delivery timeline is shared after order confirmation based on current queue.

Support terms

Complete documentation, setup guide, and viva preparation included. Support for setup and explanation provided.

Download free synopsis (PDF)

Enter your name and WhatsApp number — the synopsis PDF downloads immediately. We may send occasional project updates on WhatsApp; no spam.

Get a quotation