Skip to content

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
Step-by-step guide: how to use Homemade Machine LearningInstall, first run, examples, tips and FAQs

How to get it

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

ProjectStarsTypeLevelUpdatedBest for
homemade-machine-learning (this)24.8kLearning resourcebeginner12 months agoStudents learning the math behind machine learning algorithms
ML-For-Beginners91.9kLearning resourcebeginner5 days agoBeginners who want a structured, self-paced introduction to machine learning
100-Days-Of-ML-Code52kLearning resourcebeginner2.9 years agoBeginners who want a day-by-day sequence of basic machine learning topics
C-Plus-Plus34.8kLearning resourceintermediate1 months agoStudents learning algorithms and data structures in C++
python-machine-learning-book12.7kLearning resourcebeginner4 months agoReaders who own the 1st edition and want to run its code
MLAlgorithms11.2kLearning resourceintermediate1 months agoStudents 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.