explaingit

trekhleb/homemade-machine-learning

24,527Jupyter NotebookAudience · developerComplexity · 2/5MaintainedLicenseSetup · easy

TLDR

Educational repository implementing machine learning algorithms from scratch in Python with interactive Jupyter notebooks and mathematical explanations for each one.

Mindmap

mindmap
  root((repo))
    What it does
      Implements algorithms
      Step-by-step code
      Math explanations
    Algorithms covered
      Linear regression
      Logistic regression
      K-means clustering
      Anomaly detection
      Neural networks
    Learning format
      Plain-English math
      Python source code
      Interactive notebooks
    Use cases
      Understand algorithm internals
      Learn machine learning
      Experiment with data
      Study mathematics

Things people build with this

USE CASE 1

Learn how linear regression and logistic regression work by reading the math and running interactive notebook examples.

USE CASE 2

Understand clustering and anomaly detection by implementing K-means from scratch and experimenting with sample datasets.

USE CASE 3

Study neural network fundamentals by reading step-by-step code implementations alongside mathematical explanations.

USE CASE 4

Build intuition for machine learning by modifying algorithm code and seeing results change in real time.

Tech stack

PythonJupyter Notebook

Getting it running

Difficulty · easy Time to first run · 5min
Use freely for any purpose including commercial, as long as you keep the copyright notice.

In plain English

Homemade Machine Learning is an educational repository that implements popular machine learning algorithms from scratch in Python, with interactive notebooks and mathematical explanations alongside each one. Rather than calling a single line of code from a library, every algorithm is written out step by step so you can see exactly how it works. The algorithms covered include supervised learning techniques like linear regression (predicting a number, such as a country's happiness score) and logistic regression (categorizing inputs, such as recognizing handwritten digits). It also covers unsupervised learning like K-means clustering (grouping data by similarity without labels) and anomaly detection (spotting unusual data points). Neural networks are covered too. Each algorithm has three components: a plain-English explanation of the mathematics, the Python source code, and an interactive Jupyter Notebook demo where you can experiment with the data and see the output in your browser in real time. This is aimed at people learning machine learning who want to understand how algorithms work at a conceptual and mathematical level, not just how to call a library function. The implementation is intentionally simple and not designed for production use. The tech stack is Python, with Jupyter Notebooks as the interactive environment.

Copy-paste prompts

Prompt 1
Show me how to use the homemade-machine-learning repo to understand linear regression by walking through the notebook and modifying the input data.
Prompt 2
I want to learn K-means clustering from first principles. How do I use this repo's implementation to see how the algorithm groups data step by step?
Prompt 3
Help me understand the math behind logistic regression using the homemade-machine-learning notebooks. What does each part of the code do?
Prompt 4
How can I use the neural network implementation in this repo to learn how layers and activation functions work?
Prompt 5
Walk me through the anomaly detection algorithm in homemade-machine-learning and explain how to spot unusual data points.
Open on GitHub → Explain another repo

Generated 2026-05-18 · Model: sonnet-4-6 · Verify against the repo before relying on details.