Malcolm Low | Practical AI, Computing & Quantum Research

Singapore-based practical guides, tutorials and experiments in AI, computing, modelling, simulation, optimisation and quantum computing, with research notes and hands-on workflows.

, , ,

Pocket Data Science IV: Kaggle MNIST Subspace SVM Guide

Yes, subspace SVM hits 98% on phone. Training raw 784-D pixels triggers memory OOM freezes in Termux. See the PCA reduction pipeline & benchmark code →

·

Written by

POCKET DATA SCIENCE • PART IV

A hands-on walkthrough exploring computer vision baselines on Kaggle’s Digit Recognizer (MNIST) benchmark: from empirical random guessing and prototype centroid templates to multinomial softmax regression and PCA-accelerated non-linear ensembles on an Android phone running Termux and Google Antigravity CLI.

In our previous explorations across the Pocket Data Science series, we established systematic workflows on mobile hardware using Google Antigravity CLI (agy) inside Termux PRoot. We progressed through tabular classification with Titanic and Spaceship Titanic, and tackled continuous regression on House Prices (reaching Rank #704 / Top 18.8%). In our foundational setup guide, we also documented how to set up Google Antigravity CLI on Android with Termux PRoot.

In this fourth installment, we enter the world of computer vision using the classic Kaggle Digit Recognizer (MNIST) benchmark (42,000 training images, 28,000 test images, 784 grayscale pixels each). Before rushing into deep convolutional networks, we apply our disciplined, tiered approach: understanding empirical priors, zero-learning prototype templates, linear decision frontiers, and memory-conscious non-linear ensembles on ARM64 mobile hardware.


💻 Open-Source Code: All 10 experiment scripts, pipelines, and reproduction guides are available on GitHub: github.com/myhlow/kaggle-digit-recognizer-mnist (and in the master monorepo: myhlow/pocket-data-science).

1  ·  The Mobile ML Environment

All data loading, model fitting, validation, and Kaggle submissions were executed entirely on a consumer smartphone:

  • Host Architecture: Android 14 running Termux with a Debian userspace via PRoot Distro on 64-bit ARM (aarch64).
  • Agentic CLI: Google Antigravity CLI (agy) pair-programming in bash, managing background tasks, and verifying data pipelines.
  • Environment: Python 3.14 with pandas, numpy, scikit-learn, and the official kaggle CLI.
  • Constraints: Operating within smartphone RAM and thermal envelopes requires algorithmic efficiency (e.g., avoiding raw O(N²) distance calculations across 42k × 28k × 784 floating-point matrices).

2  ·  Progression: 10-Tier Ladder (Day 1 & Day 2 Results)

Across Day 1, we utilized all 5 available daily submissions to establish clear empirical milestones against the 862 active teams on the public leaderboard:

Experiment & Strategy Val Acc & Kaggle Public Score LB Rank & Standing
Exp 01: Empirical Random Prior N/A · Kaggle: 0.10139 (10.14%) #847 · Bottom 1.7% (15 teams beaten)
Exp 02: PCA(55) + k-NN(5) (Distance-Weighted) Val: 97.76% · Kaggle: 0.97485 #472 · Top 55% (+375 ranks)
Exp 03: PCA(55) + Linear SVM (SGD) Val: 91.80% · Kaggle: 0.91528 #682 · Top 79%
Exp 04: PCA(55) + Logistic Regression (L2) Val: 92.44% · Kaggle: 0.92214 #664 · Top 77%
Exp 05: PCA(55) + ExtraTrees (150 trees) Val: 95.12% · Kaggle: 0.94957 #582 · Top 68%
Exp 06: PCA(55) + RBF SVM (C=5.0) Val: 98.42% · Kaggle: 0.98214 #362 · Top 42% (+110 ranks)
Exp 07: 5-Model Soft Probability Blend Val: 98.60% · Kaggle: 0.98457 #318 · Top 37% (+44 ranks)
Exp 08: PCA(80) + RBF SVM + Heavy Blending Val: 98.84% · Kaggle: 0.98714 #248 / 862 · Top 28.8% (+70 ranks)

3  ·  Tier 1: Zero-Training Baselines & “Ghost Templates”

Before training parameterized models, baseline tests define the floor of predictability:

  • Empirical Random Guessing (10.14%): Drawing randomly according to class frequencies in the training set matches the theoretical expectation for 10 balanced classes (~10%).
  • Constant Majority Class (11.40%): Digit 1 is slightly more frequent than others (4,684 of 42,000 samples, or 11.15%). Predicting 1 for all 28,000 test images yielded 11.40% on Kaggle.
  • Nearest Centroid Classifier (81.45%): By simply calculating the element-wise arithmetic mean of all 4,200 training images per digit class, we obtain 10 average “ghost templates”. Classifying each test image to the template with highest cosine similarity requires zero parameter tuning or gradient updates, yet hits 81.45% accuracy, demonstrating the geometric separation already inherent in raw pixel alignments.

4  ·  Tier 2: The Linear Boundary & Non-Linear Latent Ensembles

Moving to machine learning algorithms revealed the threshold between linear and non-linear classification in 784 dimensions:

  • Multinomial Softmax Regression (92.09%): Training a linear multinomial logistic regression classifier via L-BFGS sets 10 separating hyperplanes. It achieves 92.09%, illustrating the limit of linear separability without feature expansion or spatial convolutions.
  • Dimensionality Reduction via PCA: Full k-Nearest Neighbors on raw pixels is prohibitive on phone CPUs (over 1.1 billion pairwise Euclidean distance calculations). By applying Principal Component Analysis (PCA) to compress 784 pixels to 55 components (preserving 84.0% variance), inference dropped to just 8 seconds.
  • Neighborhood + Tree Ensembling: Combining distance-weighted k-NN (k = 5) with an Extra Trees Classifier (150 trees) on raw pixel partitions raised validation accuracy to 97.96% and public leaderboard accuracy to 97.58%, vaulting past 235 teams to Rank #571.

5  ·  Exp 06: Deep MLP & Empirical Computational Profiling on Mobile ARM64

To push beyond classical decision boundaries without exceeding smartphone hardware constraints, we designed Experiment 06: a tri-blend ensemble pairing a 235k-parameter Deep Multi-Layer Perceptron (MLP(256, 128)) with our distance-weighted k-NN(5) and ExtraTrees(150) models.

On a 5,000-sample stratified holdout, the Tri-Blend achieved 98.34% accuracy (+0.38% over Exp 05), cutting classification error by 18.6%. Here is the exact training and inference computational profile measured directly on our 8-core ARM64 Android device:

Model Component & Config Training Time & Val Acc (5k) Test Inference & Throughput
PCA(55) + k-NN(5) Fit: 4.0s (37k) / 21.6s (42k) · Acc: 97.76% 8.5s (28k test) · ~3,294 samples/sec
PCA(55) + Linear SVM Fit: 1.2s (37k) / 1.5s (42k) · Acc: 91.80% 0.4s (28k test) · ~70,000 samples/sec
PCA(55) + Logistic Regression Fit: 3.8s (37k) / 4.5s (42k) · Acc: 92.44% 0.5s (28k test) · ~56,000 samples/sec
PCA(55) + ExtraTrees (150 trees) Fit: 18.2s (37k) / 22.1s (42k) · Acc: 95.12% 2.1s (28k test) · ~13,333 samples/sec
PCA(55) + RBF SVM (C=5.0) Fit: 42.5s (37k) / 54.2s (42k) · Acc: 98.42% 14.8s (28k test) · ~1,891 samples/sec
  • The Dual-Axis 126,000-Sample Breakthrough: In Experiment 10, tripling the training partition to 126,000 samples by combining both horizontal (±1px on the X-axis) and vertical (±1px on the Y-axis) translational jitter provided complete 2D shift-invariance. Fitting the entire 126,000-sample pipeline (PCA + RBF-SVM) took 3.4 minutes on phone CPU and drove our Kaggle score to 0.98792 (Rank #406 / Top 47.05%, beating 457 teams)!
  • The Latent Space Regularization Win: Projecting images onto a 55-dimensional orthogonal subspace did not just accelerate training—it acted as an optimal low-pass filter against boundary pixel noise, achieving 98.60% validation accuracy versus 98.24% on uncompressed 784 pixels while fitting 17× faster (7.2s vs 148.6s).
  • The Dual Meta-Ensemble Synergy: In Experiment 08, weighting the calibrated RBF-SVM at 90% and Deep MLP at 10% demonstrated how soft neural representations resolve ambiguous edge cases without disrupting primary maximum-margin decision planes.

6  ·  Day 2 Milestone Achieved: Top 47.05% on Mobile Hardware (Rank #406 / 863)

With Experiment 10 scoring 0.98792, we officially breached the Top 50% cutoff (0.98739, Rank #431) to claim Rank #406 out of 863 active teams worldwide, outperforming 457 competitive teams.

  • Zero GPU Resources: The entire progression—from empirical random guessing (0.10139) to classical ensembles (0.97578) and 126k dual-axis augmented subspace SVM (0.98792)—was engineered, trained, and submitted entirely on an Android smartphone CPU via Termux and Antigravity CLI.
  • Looking Ahead to Day 3: With all 5 daily submissions successfully exhausted for Day 2, our next frontier is custom lightweight Convolutional Neural Networks (LeNet-5 & Modern Compact ResNets) built directly on PyTorch ARM64 to break into the Top 20%.

Field Tests & Applications: The Pocket Data Science Series

See this Termux + Antigravity CLI setup in action across competitive machine learning benchmarks on mobile hardware:

Continue the Pocket Data Science Series


Pocket Data Science Series  ·  Tested on Android 14 / Termux  ·  Debian ARM64 PRoot  ·  Google Antigravity CLI

✦ All experiment scripts (exp01_random_baseline.py through exp10_dual_axis_augmented_svm.py) and submissions are archived locally in /root/digit-recognizer/. ✦

Comments

Leave a Reply