DEV Community

Cover image for Logistic Regression on MNIST (0 vs 1) in PHP: A Simple Example
Samuel Akopyan
Samuel Akopyan

Posted on

Logistic Regression on MNIST (0 vs 1) in PHP: A Simple Example

Want to get a real feel for machine learning in practice?

Here’s a simple but powerful exercise: classify thousands of digits (0 vs 1) from the MNIST dataset (12,666 train samples and 2,116 test samples) using logistic regression — trained with gradient descent. Just 5 epochs.

What you’ll get out of it:

  • see how a model actually works with image data
  • understand where linear models start to break down
  • try a clean implementation in pure PHP: accuracy: 99.91%
  • compare it with a more production-ready approach using RubixML: accuracy: 99.95%

If you’ve been meaning to move from theory to something hands-on, this is a great place to start:
https://aiwithphp.org/books/ai-for-php-developers/examples/part-3/logistic-regression/case-0/mnist-0-1

Top comments (0)