Skip to content
How it works · the ML workflow

From words
to a verdict.

Five stages turn a text message into a classification. Trace any message through them below; every value in the live trace is returned by the real model on the API.

Stage 01

SMS Input

The system receives raw text, exactly as typed: capital letters, punctuation, emoji and all. Nothing about the sender or phone number is used, only the words.

Live traceunavailable

Start the FastAPI backend to see real values at each stage.

APlain-language notes

The ideas,
without the jargon.

01

Supervised learning

During training the algorithm saw 4,100 messages together with their correct labels. It learned which patterns of words go with each label. New messages arrive with text only.

02

Why not keyword rules?

A rule like “flag every message containing free” would hide “When you get free, call me”. A model weighs many words at once and learns the weights from data, though it can still make that mistake.

03

Why TF-IDF?

Counting words over-rewards common ones. TF-IDF boosts words that are distinctive for a message and shrinks words that appear everywhere. Values are normalised so long and short messages are comparable.

04

Why Naive Bayes?

It was compared fairly with Logistic Regression on the same folds and features. It scored higher mean spam F1 in validation (92.02% vs 91.13%) and then held up on unseen messages.

BSystem architecture

Trained once.
Served instantly.

The pipeline is fitted offline by train.py, saved with joblib, and loaded once when the API starts. Each request reuses it without retraining.

  1. spam.csv
    5,572 rows
    →
  2. train.py
    clean · split · 5-fold grid search
    →
  3. selected_pipeline.joblib
    TF-IDF + MultinomialNB(α=0.1)
    →
  4. FastAPI
    POST /api/predict
    →
  5. Next.js
    Detection Studio