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: Tackling Kaggle MNIST on Android with Antigravity CLI — From Zero-Parameter Baselines to Top 47% Subspace SVM

A hands-on walkthrough exploring zero-parameter baselines, orthogonal PCA subspaces, spatial data augmentation, and RBF-SVM on Kaggle Digit Recognizer (MNIST) on Android via Termux and Antigravity CLI.

·

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.
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:

Exp Model & Strategy Validation Acc Kaggle Public Score LB Rank Percentile Teams Beaten
Exp 01 Empirical Random Prior N/A 0.10139 (10.14%) #847 Bottom 1.7% 15
Exp 02 Constant Majority Class (Digit 1) 11.15% 0.11403 (11.40%) #846 Bottom 1.9% 16
Exp 03 Nearest Mean Centroid (“Ghost Templates”) 81.38% 0.81446 (81.45%) #835 Top 96.9% 27
Exp 04 Multinomial Softmax Logistic Regression 92.20% 0.92089 (92.09%) #806 Top 93.5% 56
Exp 05 PCA(55) + k-NN(5) & ExtraTrees(150) Blend 97.96% 0.97578 (97.58%) #571 Top 66.2% 292
Exp 06 Tri-Blend: MLP(256, 128) + k-NN(5) + ExtraTrees(150) 98.34% 0.98085 (98.09%) #523 Top 60.7% 339
Exp 07 Orthogonal Manifold + RBF-Kernel SVM (C=5) 98.60% 0.98453 (98.45%) #487 Top 56.4% 376
Exp 08 Dual Meta-Ensemble: 90% RBF-SVM + 10% Deep MLP 98.66% 0.98514 (98.51%) #481 Top 55.7% 382
Exp 09 Translation-Augmented Orthogonal Subspace SVM (84k train) 98.68% 0.98696 (98.70%) #438 Top 50.8% 425
Exp 10 3× Dual-Axis Spatial Augmentation + Subspace SVM (126k train) 98.78% 0.98792 (98.79%) #406 Top 47.05% 457
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 Complexity / Config Val Fit (37k) Val Acc (5k) Full Fit (42k) Test Inference (28k) Throughput
PCA(55) + k-NN(5) Latent Metric Space (Distance-weighted) 4.0s 97.76% 21.6s 8.5s ~3,294 img/s
ExtraTrees(150) 150 Trees, 784 pixels (8 CPU cores) 5.6s 96.98% 21.2s 0.7s ~40,000 img/s
MLP(256, 128) 235,146 params, Adam, 25 epochs 262.0s 98.00% 322.2s 4.2s ~6,667 img/s
Tri-Blend (40/30/30) 40% MLP + 30% k-NN + 30% ET 271.6s 98.34% 365.0s (6.1 min) 13.4s ~2,090 img/s
PCA(55) + RBF-SVM (Exp 07) Infinite-Dim RBF Kernel (C=5) 5.7s (8.5s w/ PCA) 98.60% 7.2s (22.5s w/ PCA) 19.6s ~1,425 img/s
Dual Meta-Ensemble (Exp 08) 90% RBF-SVM + 10% Deep MLP 364.6s 98.66% 544.1s (9.1 min) 36.7s ~763 img/s
Augmented RBF-SVM (Exp 09) 2× Spatial Jitter + PCA(55) + SVM 50.8s (74k train) 98.68% 51.4s (84k train) 52.9s ~529 img/s
Dual-Axis Aug Subspace SVM (Exp 10) 3× Dual-Axis Spatial Jitter (126k) + PCA(55) + SVM 91.8s (111k train) 98.78% 205.6s (3.4 min, 126k) 168.9s (2.8 min) ~166 img/s
  • 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%.

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 comment