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.
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.
Start the FastAPI backend to see real values at each stage.
The ideas,
without the jargon.
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.
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.
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.
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.
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.
- →spam.csv5,572 rows
- →train.pyclean · split · 5-fold grid search
- →selected_pipeline.joblibTF-IDF + MultinomialNB(α=0.1)
- →FastAPIPOST /api/predict
- Next.jsDetection Studio