Noureddine RAMDI / ML-From-Scratch: Exploring Machine Learning Fundamentals with Pure Python and NumPy

Created Sat, 23 May 2026 20:41:14 +0000 Modified Sat, 23 May 2026 20:41:27 +0000

eriklindernoren/ML-From-Scratch

ML-From-Scratch tackles the common challenge of understanding machine learning algorithms beyond black-box libraries. Instead of reaching straight for PyTorch or TensorFlow, this repository presents core ML methods implemented purely with Python and NumPy. The result is a collection of transparent, minimalistic code that exposes the mathematical heart of algorithms from linear regression to GANs and neuroevolution.

What ML-From-Scratch offers and how it’s structured

This repository is essentially an educational toolkit that implements fundamental machine learning models and algorithms from the ground up. It covers a broad spectrum of ML approaches: supervised learning (including linear regression, logistic regression, and convolutional neural networks), unsupervised learning (DBSCAN clustering, restricted Boltzmann machines, generative adversarial networks), reinforcement learning (Deep Q-Network applied to CartPole), and evolutionary algorithms (neuroevolution and genetic algorithms).

The entire codebase is written in Python using only NumPy for numerical operations. There are no dependencies on heavy ML frameworks, which means the code is surprisingly approachable and readable. Each algorithm is implemented in a standalone Python file, allowing you to read and understand the core logic without wading through a complex library.

Architecturally, the repository is modular, with a clear separation between different ML paradigms and algorithms. This design makes it easy to focus on one concept at a time or to compare different approaches side by side. For example, you can directly inspect the convolutional neural network implementation and see how the forward and backward passes are coded from scratch.

Why the repository stands out technically and its tradeoffs

What distinguishes ML-From-Scratch is its commitment to educational transparency rather than production-ready performance. The code prioritizes clarity and mathematical exposition over optimization. This means you won’t find GPU acceleration, parallel processing, or any of the performance tricks that modern ML libraries employ.

The tradeoff is clear: these implementations are not designed for large datasets or production workloads. However, they provide invaluable insight into the nuts and bolts of ML algorithms. For example, the neuroevolution example evolves a neural network using a genetic algorithm, achieving a test accuracy of 96.7% on MNIST after 3000 generations. This is an insightful demonstration that backpropagation isn’t the only way to train neural networks.

Benchmarks included in the README highlight the practical results of these minimal implementations: the convolutional neural network reaches an accuracy of 0.987 on a digit dataset, the GAN generator model contains 1,489,936 parameters, and the Deep Q-Network setup includes 450 total parameters. These numbers give a sense of scale and complexity despite the simplicity of the code.

The project also covers advanced topics like reinforcement learning with Deep Q-Networks and unsupervised models such as restricted Boltzmann machines, which are rarely covered in such a transparent manner. The code’s quality is generally clean and well-commented, making it suitable for learners who want to trace data flow and gradient computations step by step.

Quick start

The repository provides straightforward installation commands in its README:

$ git clone https://github.com/eriklindernoren/ML-From-Scratch
$ cd ML-From-Scratch
$ python setup.py install

Once installed, you can explore the standalone scripts implementing various algorithms. The README and individual Python files contain usage examples and explanations, allowing you to run models directly and see how they behave on datasets like MNIST or CartPole.

Verdict

ML-From-Scratch is a valuable resource for developers and students who want to build a solid, hands-on understanding of machine learning fundamentals by reading and running minimal code. It’s particularly well-suited for those who find high-level ML frameworks opaque and want to see the math realized in Python line by line.

That said, it is not intended for production use or large-scale experiments. The implementations lack performance optimizations and advanced features like parallelization or hardware acceleration. Nonetheless, the educational clarity it offers is worth the tradeoff for anyone serious about grasping how ML algorithms work under the hood.

If your goal is to learn, teach, or experiment with core ML concepts in a clean and digestible way, ML-From-Scratch is a repository to bookmark and explore.


→ GitHub Repo: eriklindernoren/ML-From-Scratch ⭐ 31,514 · Python