Model or dataset
eriklindernoren/ML-From-Scratch avatar
eriklindernoren/ML-From-Scratch

ML-From-Scratch: A Bare-Bones NumPy Tour of Machine Learning Internals

GitHub describes it as Machine Learning From Scratch. Bare bones NumPy implementations of machine learning models and algorithms with a focus on accessibility. Aims to cover everything from linear regression to deep learning.. The repository metadata lists Python as its primary language. The metadata lists the MIT license. This article stays within the project description and details documented in the GitHub repository README.

33,422 stars5,539 forksPythonMIT

At a glance

What is it?
This repository reimplements fundamental ML models and algorithms in bare NumPy, trading speed for readability. It is a teaching tool, not a production library, and that distinction drives every design choice.
Who is it for?
Adopt ML-From-Scratch if you are a student, educator, or engineer who wants to read the actual math of a model in code, without a framework's abstraction. Do not use it for any performance-sensitive task, large dataset, or production deployment; the documentation explicitly says it prioritizes transparency over efficiency.
Can I use it commercially?
Yes. MIT is a permissive licence: you can use, modify and sell software built on it, as long as you keep its copyright and licence notices.
Is it still maintained?
Probably not. The repository last received commits 37 months ago, on October 15, 2023.
What is it written in?
Mainly Python, according to GitHub's language statistics.

Answers come from the project's GitHub data, last synced on November 23, 2026, and from our analysis. They are not legal advice.

From daily snapshots

Star history

  • eriklindernoren/ML-From-Scratch33,422 ★ · +965
Star history
Repository2026-08-132026-11-23
eriklindernoren/ML-From-Scratch32.5k33.4k

965 Stars in the last 102 days, measured from the daily GitHub snapshot. Compare with other projects

Editorial analysis

What This Repository Actually Is

ML-From-Scratch is a collection of Python files that implement machine learning models from linear regression to deep reinforcement learning, using bare-bones NumPy. The README states the purpose is not to produce optimized or computationally efficient algorithms, but to present the inner workings in a transparent and accessible way. That sentence is the entire value proposition. It is aimed at people who want to see how a support vector machine or a restricted Boltzmann machine works at the level of matrix operations, not at practitioners who need to train models on real data. The repository is a teaching artifact, closer to a code-first textbook than a library. The author, Erik Linder-Noren, organized the implementations into supervised, unsupervised, reinforcement, and deep learning sections, with example scripts that run standalone. If you have ever wondered what a backpropagation loop looks like when you cannot call model.fit(), this is the place.

The Mechanism: NumPy Arrays and Explicit Loops

The implementations are built on NumPy arrays rather than a deep learning framework. The README shows a convolutional neural network example that prints a layer-by-layer summary with parameter counts, and the training output reports accuracy after a full pass. That summary is generated by the repository's own code, which means the library includes a model summary utility that walks through layers and counts parameters. The data flow is straightforward: example scripts load data, instantiate a model, call a fit or train method, and then evaluate. For a GAN, the README shows separate generator and discriminator networks, each built from dense layers and activation functions, with batch normalization in the generator and dropout in the discriminator, trained against each other. The transparency comes at a cost: every operation is explicit, so you can read the math, but the code is longer and slower than a framework equivalent.

Installation and First Run: Commands You Can Copy

The README gives a three-step installation: clone the repository, change into the directory, and run python setup.py install. That is the only documented method. There is no mention of pip install from PyPI, and no virtual environment instructions; the repository does include a requirements.txt, which lists its dependencies without version pins. After installation, you run examples by invoking scripts directly, such as python mlfromscratch/examples/polynomial_regression.py or python mlfromscratch/examples/dbscan.py. The polynomial regression example fits temperature data from Linköping, Sweden, 2016, showing a regularized model. The CNN example trains on a digit dataset and prints accuracy around 0.987. The deep Q-network example solves CartPole-v1 from OpenAI gym. These commands are simple; setup.py reads requirements.txt, which lists numpy, scipy, matplotlib, pandas, cvxopt, gym and others. The setup.py install approach is dated; modern Python packaging would use pyproject.toml and pip. If you are on a recent Python version, you may need to adjust the installation step manually.

Coverage: From Linear Regression to Neuroevolution

The repository's table of contents lists implementations across four categories. Supervised learning includes regression and classification models. Unsupervised learning covers clustering, dimensionality reduction, and generative models like the restricted Boltzmann machine and GAN. Reinforcement learning includes a deep Q-network. Deep learning includes convolutional networks and other architectures. The examples section also shows a genetic algorithm and an evolutionary evolved neural network, which are not typical in a standard ML curriculum. The README's example list is long: polynomial regression, CNN classification, DBSCAN clustering, GAN digit generation, deep reinforcement learning, RBM image reconstruction, neuroevolution, genetic algorithm, and association analysis. That breadth is the repository's main strength. You can compare how different algorithms approach the same problem, like generative modeling with a GAN versus an RBM. You should inspect the repository tree to confirm coverage before relying on it for a specific algorithm.

A Real Limitation: No Performance, No Guarantees

The documentation is explicit that the algorithms are not optimized. That is a genuine limitation if you try to use this on any dataset larger than a toy problem. The CNN example trains on an 8x8 input and takes nearly two minutes to train (Time: 0:01:55), according to the README output. A real-world image dataset would be infeasible. The repository has no GitHub releases, and the last push was on 2023-10-15. That means you cannot assume active maintenance. For a student, that is fine. For an engineer evaluating it for a project, it is a dealbreaker. The wrong tool scenario is any situation where you need to train a model on a laptop with a realistic dataset, or where you need to integrate with a deep learning framework for GPU acceleration. The repository explicitly disclaims efficiency, so you should not be surprised when training is slow.

The Alternative: Read a Textbook, or Use a Framework

The natural alternative is not another library; it is a machine learning textbook with code, like Bishop's Pattern Recognition and Machine Learning, or a framework like PyTorch or TensorFlow. The difference in approach is fundamental. A framework like PyTorch gives you automatic differentiation, GPU support, and a large ecosystem, but it hides the gradient computation behind a backward() call. ML-From-Scratch shows you the gradient computation in plain NumPy, which is educational but not practical for training. Another alternative is a tutorial-based repository like Karpathy's micrograd, which implements autograd in a few hundred lines. Micrograd is smaller and focuses on the core mechanism of backpropagation, while ML-From-Scratch covers a wider range of algorithms. If you want to understand one algorithm deeply, a focused tutorial may be better. If you want a survey of many algorithms in one codebase, ML-From-Scratch is more comprehensive. The choice depends on whether you want breadth or depth, and whether you intend to run the code or just read it.

Maintenance and License: What You Are Signing Up For

The repository is licensed under the MIT license, which permits commercial use, modification, and distribution with attribution. That is a permissive license, so you can adapt the code for your own educational materials without legal friction, though this is not legal advice. The maintenance picture is less clear. The metadata shows no GitHub releases, and the last push was on 2023-10-15. setup.py gives the version as 0.0.4, and the repository has no changelog file. That means you cannot expect bug fixes or updates. The dependencies are listed in requirements.txt (numpy, scipy, matplotlib, pandas, cvxopt, gym and others) without version pins. If NumPy changes its API, the code may break. The setup.py install method is also a maintenance risk, as it is not the current Python packaging standard. For a student, this is acceptable because you are reading code, not deploying it. For a team, you would need to fork and maintain it yourself. The trade-off is clear: you get transparency, but you give up ongoing support.

Who Should Use It and Who Should Stay Away

This repository is for learners who want to read the implementation of an algorithm and understand the math behind it. It is also useful for educators who want to show students a complete, runnable implementation without the noise of a framework. The examples are self-contained, so you can run them and see the training progress. The CNN example prints a detailed layer summary, which is a nice feature for teaching. However, if you are a practitioner who needs to train a model for a real task, or if you need to benchmark algorithms on your own data, this is the wrong tool. The repository does not provide any performance guarantees, and the code is intentionally slow. If you are evaluating it for adoption in a project, the first thing to verify is whether the specific algorithm you need is implemented and whether it works with your Python version. The second thing is to check the repository's commit history; the last push was on 2023-10-15. The third is to run the example scripts yourself to see if they execute without errors. Only then can you decide if the educational value outweighs the lack of support.

Editorial conclusion

Adopt ML-From-Scratch if you are a student, educator, or engineer who wants to read the actual math of a model in code, without a framework's abstraction. Do not use it for any performance-sensitive task, large dataset, or production deployment; the documentation explicitly says it prioritizes transparency over efficiency. Before relying on it, verify that the algorithm version you need is present, check the last commit date for maintenance, and test the examples on your Python environment, since setup.py install is the only documented path and there are no pinned dependencies. The right move is to treat it as a reference textbook, not a dependency.

Frequently asked questions

How do I install ML-From-Scratch?

Clone the repository and run `python setup.py install` from the root, as the README's Installation section shows. The package installs under the name `mlfromscratch` and its dependencies come from requirements.txt, which pins no versions.

How do I run a single model in ML-From-Scratch?

Each example is a standalone script you execute directly, for example `python mlfromscratch/examples/polynomial_regression.py` or `python mlfromscratch/examples/convolutional_neural_network.py`. The library provides the implementations; the example scripts wire up the data and print the results.

Does ML-From-Scratch include deep reinforcement learning?

Yes. There is a deep reinforcement learning example, `python mlfromscratch/examples/deep_q_network.py`, which is presented as a Deep Q-Network solution to the CartPole-v1 environment in OpenAI gym. The requirements also list gym.

What is the license of ML-From-Scratch?

The repository is MIT licensed, and setup.py declares the same MIT license with author Erik Linder-Noren. The intent is that you can read the code and reuse it in your own projects.

Is ML-From-Scratch good for production use?

No. The project states its purpose is to present the inner workings of algorithms in a transparent way rather than to produce optimized, computationally efficient ones. It is written in plain NumPy with no speed optimizations, so it suits reading and learning, not deployment.

Official sources

  1. Official README
  2. Project repository
  3. README
  4. Releases
Community

Where developers are discussing it

Posts on Hacker News, dev.to and Lobsters that link to this repository, found by our scan of those communities. 1 in the last 30 days; newest first.

Add this badge to your README

If you maintain this project, the badge below links readers to this analysis and shows its maintenance status from the daily GitHub snapshot. Paste the markdown into your README; add ?metric=license or ?metric=stars to the image URL for a different field.

Add this badge to your README

markdown
[![Hysen Labs](https://hysenlabs.com/badge/eriklindernoren-ml-from-scratch.svg)](https://hysenlabs.com/projects/eriklindernoren-ml-from-scratch)

Star history chart for your README

markdown
[![Star history](https://hysenlabs.com/chart/eriklindernoren-ml-from-scratch.svg)](https://hysenlabs.com/projects/eriklindernoren-ml-from-scratch)

Was this useful?