Machine Learning  ·  Internship Month 01

Two classifiers.
One reads text, one reads pixels.

A spam filter trained on real email data, and a digit reader trained on 42,000 handwritten samples from Kaggle's MNIST set — built, evaluated, and tested end to end in Python.

live_check.py
97.0%
Spam detection accuracy
96.6%
Digit recognition accuracy
47.7K
Labelled samples trained on
01
CASE 01

Email Spam Classification

Every message boils down to one question: does the pattern of words look like something a person wrote, or something designed to get clicked? The model answers by reading term frequency, not by reading intent.

Pipeline

  • 01Clean the raw text — lowercase, strip URLs, digits, and punctuation.
  • 02Vectorize with TF-IDF across unigrams and bigrams, capped at 3,000 features.
  • 03Train two candidates — Multinomial Naive Bayes and Logistic Regression — on an 80/20 stratified split.
  • 04Score both on precision, recall and F1, then keep the stronger model.

Spec sheet

datasetKaggle · Ashfak Yeafi
samples5,572 messages
split4,825 ham / 747 spam
featuresTF-IDF · 3,000 dims
modelMultinomial Naive Bayes
accuracy97.0%
spam precision1.00
Confusion matrix for the spam classifier
fig. 01 — confusion matrix, best model
Model comparison chart
fig. 02 — Naive Bayes vs Logistic Regression

Sample readouts

"Congratulations! You've won a free iPhone, click here to claim now!!!"SPAM
"Hey, are we still meeting for lunch tomorrow?"HAM
"URGENT: your account will be suspended, verify your password immediately"SPAM
"Can you send me the report before 5pm?"HAM
Interactive mode — the script drops into a live prompt after training: type any message and get an instant spam/ham verdict from the trained model.

Try it live — runs the real trained model, in your browser

This calls the actual Naive Bayes weights and TF-IDF vocabulary exported from training — not a simulation.

02
CASE 02

Handwritten Digit Recognition

Every digit arrives as 784 numbers — one per pixel, brightness 0 to 255, no picture file involved. The model never sees a "3"; it sees a specific arrangement of light and dark, and learns which arrangements repeat.

Pipeline

  • 01Flatten each 28×28 image into a 784-value vector and standardize pixel intensities.
  • 02Split 42,000 labelled images 80/20, stratified across all ten digits.
  • 03Train two candidates — an RBF-kernel SVM and a 200-tree Random Forest.
  • 04Score both on accuracy and a full per-digit report, then keep the stronger model.

Spec sheet

datasetKaggle · Digit Recognizer
samples42,000 images
resolution28 × 28 px
features784 scaled pixels
modelRandom Forest · 200 trees
accuracy96.6%
most confused3 / 5, 4 / 9
Confusion matrix for the digit classifier
fig. 03 — confusion matrix, all ten digits
Sample digit predictions
fig. 04 — ten test images, predicted vs. actual
Interactive mode — pick any test image by index, or ask for a random one, and the script saves a picture of that exact digit next to the model's live prediction.

Try it live — 200 real held-out test images

Each one is an actual Kaggle MNIST image the model never trained on, with its real prediction from the trained Random Forest.

200 samples drawn from an 8,400-image held-out test set.

Built with

Python 3.14 scikit-learn pandas NumPy TF-IDF Naive Bayes Logistic Regression SVM Random Forest Matplotlib Seaborn