
Homemade Machine Learning
Python implementations of classic machine learning algorithms, written from scratch, with Jupyter demos.
- Stars
- 24.8k
- Forks
- 4.2k
- Licence
- MIT
- Language
- Jupyter Notebook
- Last update
- 12 months ago
- Type
- Learning resource
What it is
This repository contains Python code for popular machine learning algorithms such as linear regression, logistic regression, k-means clustering, anomaly detection and a multilayer perceptron neural network. Each algorithm comes with a short explanation of the math and an interactive Jupyter Notebook demo you can run in your browser. The code is written from scratch rather than with third-party library calls, so people can learn how the algorithms work. The README states it is not intended for production use.
- Run the linear regression demo to predict a country's happiness score from GDP
- Run the logistic regression demo to classify Iris flowers by petal measurements
- Run the k-means demo to group Iris flowers into clusters
- Run the MNIST demos to recognize handwritten digits with logistic regression or a neural network
- Read the math notes alongside the matching Python code files
Great for
- Students learning the math behind machine learning algorithms
- Developers who want to see simple from-scratch implementations of common algorithms
- Learners following along with Andrew Ng's machine learning course concepts
- Anyone who wants to tweak training data and see results in a notebook
Not ideal for
- Production systems, since the README says the implementations are not intended for production use
- People who need state-of-the-art models or large-scale performance, since the focus is on understanding rather than speed
- Readers who want a ready-made library to call with one line of code, since the project deliberately avoids library one-liners
How to get it
- 1
Clone and build from source
You'll need: Python · Jupyter Notebook
Clone the repository
git clone https://github.com/trekhleb/homemade-machine-learning.git - 2
Run it
- Install Python following the link in the README and optionally create a venv
- Install Jupyter Notebook
- Open the notebooks folder in Jupyter
- Open a demo notebook such as linear_regression/univariate_linear_regression_demo.ipynb and run its cells
- 3
Get the most out of it
- Read the math page for each algorithm before running its demo
- Change the training data or algorithm settings in a notebook and observe how the results change
- Compare the from-scratch code in the homemade folder with the notebook demos
- Use the Binder badge in the README to try the notebooks without local setup
Downloads
Strengths
- Explains the math behind each algorithm alongside the code
- Interactive notebook demos let you change data and settings and see results immediately
- Permissively licensed under MIT
Trade-offs
- The README says implementations are not intended for production use
- Covers a limited set of algorithms, mostly from supervised and basic unsupervised learning
- The README is truncated and does not list detailed setup commands, so setup details are unclear from the provided text
How it compares
| Project | Stars | Type | Level | Updated | Best for |
|---|---|---|---|---|---|
| homemade-machine-learning (this) | 24.8k | Learning resource | beginner | 12 months ago | Students learning the math behind machine learning algorithms |
| ML-For-Beginners | 91.9k | Learning resource | beginner | 5 days ago | Beginners who want a structured, self-paced introduction to machine learning |
| 100-Days-Of-ML-Code | 52k | Learning resource | beginner | 2.9 years ago | Beginners who want a day-by-day sequence of basic machine learning topics |
| C-Plus-Plus | 34.8k | Learning resource | intermediate | 1 months ago | Students learning algorithms and data structures in C++ |
| python-machine-learning-book | 12.7k | Learning resource | beginner | 4 months ago | Readers who own the 1st edition and want to run its code |
| MLAlgorithms | 11.2k | Learning resource | intermediate | 1 months ago | Students who want to see how algorithms work step by step |
Stats synced from GitHub. The assessment above was drafted with AI from the project's README on 2026-10-29 and may miss recent changes — check the README before relying on a command. MIT licence: free to use, modify and distribute, including commercially, as long as you keep the copyright notice.