Skip to content
Harshith Varma

The Book

ML from Scratch

Volume 1 · Foundations

Learn machine learning by building it.

Author
N Sai Harshith Varma
Pages
373
ISBN
979-8-1852-8008-9
Edition
First edition, 2026
Cover of ML from Scratch — Volume 1 · Foundations, by N Sai Harshith Varma

01Why I wrote this

I'm Harshith Varma, a Data Scientist at Confluent. I'm not someone who knows everything about machine learning. I'm someone who wants to understand everything about machine learning. Most ML resources teach you what to do — import this, call this function — but not why it works. That gap in my own understanding is what pushed me to start deriving every algorithm from scratch instead of treating ML as a toolbox. My goal isn't for you to finish this book. It's for you to reach the point where you can look at any machine learning model and think: "I understand why this works." You don't need a PhD to read this book. You only need a willingness to ask "why?" one more time than most people do. Welcome to the journey. Let's build machine learning from scratch.

02Who this book is for

Twenty chapters, four parts: Math Foundations, Build a Neural Net, PyTorch, and Training. Read them in order. Every chapter builds something the next one uses. Every chapter carries the same three code layers, in the same order: pure Python (every multiplication shown), NumPy (vectorized), then PyTorch (what you'd write at work). Four recurring callouts do the rest of the teaching — Insight for the key idea, Warn for practical failure modes, Challenge for a do-it-now exercise, and Personify, where a concept explains itself in first person. Every interactive widget on the companion website (ml.harshithvarma.in) becomes a static figure in the book, plus a pointer back to the live version. The figures are honest — you can read this book cover to cover offline. But the widgets let you move the sliders yourself, and moving the sliders is how the intuition sticks.

03Volumes & roadmap

  1. Vol. 1

    Foundations

    Available · Chapters 120

    The first twenty chapters. Gradient descent through a trained digit classifier — every derivation shown, every line of code earned.

    • Math Foundations
    • Build a Neural Net
    • PyTorch
    • Training
  2. Vol. 2

    Deep Learning: From CNNs to GPT

    Drafted · Chapters 2148

    Convolution through a working GPT you train and talk to. Fully drafted; not yet through the full review gate or published.

    • CNNs & Vision
    • RNN & LSTM
    • NLP
    • Attention & Transformers
    • Build GPT
  3. Vol. 3

    Sections 10–14 (planned)

    Planned · Chapters 4975

    Scope is set; chapters have not been drafted yet.

    • Fine-Tuning & RLHF
    • Mixture of Experts
    • Diffusion Models
    • Reinforcement Learning
    • Inference & Serving

04Table of contents — Volume 1

Math Foundations

  1. 01Gradient Descent

    A blindfolded walk down a mountain.

  2. 02Sigmoid & ReLU

    A dimmer switch and a light switch.

  3. 03Softmax

    The pollster who turns opinions into percentages.

  4. 04Cross-Entropy Loss

    The grading rubric that punishes confident lies.

  5. 05Linear Regression (Forward)

    A ruler laid across a point cloud.

  6. 06Linear Regression (Training)

    Two doors, one room.

Build a Neural Net

  1. 07Single Neuron

    A doorman, a clipboard, and one decision.

  2. 08Backpropagation

    Reading the day backwards, one local slope at a time.

  3. 09Multi-Layer Backpropagation

    The org chart learns to take blame.

  4. 10Backprop Ninja

    A lab assistant with a ruler, watching you work.

  5. 11MLP from Scratch

    Six lessons of parts. Today you bolt them into a car.

  6. 12Weight Initialization

    The sound guy fumbles the volume knobs before the band walks on.

PyTorch

  1. 13PyTorch Basics

    A scribe who sits beside you and writes down every move.

  2. 14Layer Normalization

    The per-track sound mixer in every transformer block.

  3. 15Batch Normalization

    The teacher who grades on the curve: one exam question at a time.

  4. 16RMS Normalization

    The step we found we didn't need.

Training

  1. 17Training Loop

    Forward. Loss. Backward. Step. Repeat a million times.

  2. 18Training Diagnostics

    The stethoscope lesson.

  3. 19Dead ReLU Detector

    The electrician's checklist for a chandelier that looks fine but isn't.

  4. 20Digit Classifier

    The first vehicle rolls off the assembly line.

05Read a preview

The full Volume 1 manuscript — the same file behind the Download PDF button above, ready to read in your browser's own PDF viewer.

Open full PDF (opens in a new tab)

06Companion learning site

Every derivation and figure in this book started life as an interactive lesson. The live site covers all 14 sections and 75 lessons with runnable widgets — read the book, then go move the sliders.

ml.harshithvarma.in (opens in a new tab)

07Frequently asked questions

No. The book assumes curiosity, not expertise — you need to read Python and remember some calculus. It rewards attention rather than spoon-feeding, but nothing here requires formal training beyond that.

08About the author

N Sai Harshith Varma is a Data Scientist at Confluent, where he builds AI-powered systems professionally. His fascination with machine learning has always been driven by a simple question: why does this actually work? That curiosity has led him to derive algorithms from first principles, implement them in pure Python before reaching for libraries, and share what he learns through articles, open-source projects, educational content, and hands-on workshops at universities. Beyond his work at Confluent, he enjoys building machine learning systems from scratch, exploring large language models, participating in data science competitions, and helping students and developers develop a deeper understanding of AI. He believes that understanding comes not from memorizing APIs, but from knowing what happens underneath them. ML from Scratch is the first book in a series dedicated to making machine learning transparent, intuitive, and deeply understandable, one algorithm at a time.