SMS Spam Classification

An SVM text classifier that separates spam from legitimate SMS messages using TF-IDF features, tuned with GridSearchCV.

Abstract illustration of text messages turning into a TF-IDF matrix and an SVM decision boundary.
My role
Data Science Intern
Type
Internship
Timeline
Apr — May 2024
Status
Internship project

Stack

  • Python
  • scikit-learn
  • SVM
  • TF-IDF
  • GridSearchCV
  • Text preprocessing

Reported results

  • 98%

    Reported classification accuracy

    On the project's evaluation data. Accuracy alone can overstate performance on imbalanced data.

On this page
  1. Overview
  2. The problem
  3. Pipeline
  4. Approach
  5. Results
  6. Limitations

Overview

Built during my data science internship at Personifwy: a supervised text-classification pipeline that labels SMS messages as spam or legitimate (ham).

The model reached a reported 98% classification accuracy. This write-up covers the pipeline and, just as importantly, what that number does and doesn't tell you.

The problem

SMS spam detection is a classic binary text-classification problem: given a short message, decide whether it is spam or a legitimate ("ham") message. SMS text is short, informal, and full of abbreviations, so the pipeline has to turn noisy text into features a model can learn from.

Pipeline

From raw messages to a spam/ham prediction.

6 layers · select a layer for details

  1. Input Labelled SMS messages

    Short text messages labelled as spam or ham.

  2. Preprocess Text cleaning & normalization

    Raw text is cleaned so formatting noise doesn't become a feature.

    • Python
  3. Features TF-IDF vectorization

    Messages become sparse, term-weighted vectors.

    • scikit-learn
    • TF-IDF
  4. Model Support Vector Machine

    A binary classifier trained on the TF-IDF features.

    • SVM
  5. Tuning GridSearchCV

    Cross-validated search over hyperparameters.

    • GridSearchCV
  6. Output spam / ham

    Predicted label, evaluated with classification accuracy.

Approach

Text preprocessing

Messages were cleaned and normalized before feature extraction, so that superficial differences in formatting wouldn't become features in their own right.

Feature extraction with TF-IDF

TF-IDF (term frequency–inverse document frequency) turns each message into a sparse vector that weights words by how characteristic they are of that message relative to the whole collection. Words that appear everywhere count for little; distinctive ones — the kind common in promotional spam — count for more.

Training a Support Vector Machine

A Support Vector Machine learns a decision boundary that separates the two classes with the widest possible margin. SVMs work well with high-dimensional, sparse features like TF-IDF vectors.

Hyperparameter tuning with GridSearchCV

GridSearchCV evaluated combinations of model hyperparameters with cross-validation and selected the best-performing configuration.

Results

The final model achieved a reported 98% classification accuracy on the project's evaluation data.

Limitations

  • Accuracy isn't the whole story. Spam datasets are usually imbalanced, so a model can score highly on accuracy while still missing spam. Precision, recall, and a confusion matrix give a fuller picture — they're what I'd report alongside accuracy in a follow-up.
  • Results are dataset-dependent. Performance was measured on the project's dataset. Spam patterns change over time and across regions, so results won't automatically transfer to other message sources.
  • A learning project, not a live filter. This was built as an internship project, not as a production filtering service.
Abstract illustration of imbalanced class bars being balanced, next to a logistic curve. Internship project

Machine learning Internship

Hate Speech Detection

A Logistic Regression text classifier for hate-speech detection, using SMOTE to address class imbalance.

  • Python
  • scikit-learn
  • Logistic Regression
  • SMOTE
  • and 1 more
Abstract illustration of a clinical dashboard with intake form, schedule, and SOAP-note panels. Contains no real data. In production

Healthcare software Professional

EMR & Patient Intake Platform

A production Electronic Medical Record platform covering patient intake, clinical documentation, scheduling, billing, and practice administration.

  • Python
  • Django
  • Django REST Framework
  • JavaScript
  • and 7 more
Login I Lanexis PVT LTD - customer.lanexis.com Completed and deployed

Business platform Client project

Lanexis Customer Portal

A B2B customer portal I planned, designed, built, and deployed end to end Django backend, React Native/Expo app, Google Sheets integration, and AWS infrastructure.

  • Django
  • Django REST Framework
  • React Native
  • Expo
  • and 7 more

→Get in touch

Working on something similar?

I’m happy to talk through the problem, the trade-offs, and how I’d approach it.