How to learn machine learning.
Machine learning is a small number of ideas, used over and over. Learn them in the right order and each one makes the next easy. This is that order, with a free chapter for each step.
The short version
- Learn what "learning" means on the simplest model there is, a straight line: fitting it, training it step by step with gradient descent, and checking that it works on data it has not seen. Everything else builds on this.
- Learn to predict categories. Logistic regression, nearest neighbours, naive Bayes and support vector machines are four different answers to the same question, and how to score a classifier honestly matters as much as any of them.
- Build a neural network yourself, one piece at a time, so that deep learning is something you understand rather than a library you call.
- Pick up the mathematics as you need it. Vectors, derivatives and probability, only as much as the next chapter uses.
The path, chapter by chapter
Part 0: Toolkitabout 1 h
The three pieces of mathematics the rest of the book leans on. Each chapter covers only what later chapters use, with pictures before formulas. Read them first, or come back when a chapter sends you here.
- Toolkit 0.1: Vectors and Matrices — Lists of numbers, the dot product, and what a matrix does to a vector.
- Toolkit 0.2: Derivatives and Gradients — Slope by nudging, partial derivatives, and the chain rule.
- Toolkit 0.3: Probability — Random variables, the normal curve, and Bayes' rule.
Part I: Learning from Dataabout 1 h
What it means for a machine to learn, shown on the simplest model there is, a straight line. By the end you will have fitted a model, trained it step by step, and learned how to tell whether it will work on data it has not seen.
You need: School algebra. The toolkit chapters help from chapter 3 onward.
- Chapter 1: What Is Learning? — Features, labels, and what it means for a program to learn from examples.
- Chapter 2: Linear Regression — Fitting a straight line to data, and measuring how well it fits.
- Chapter 3: Gradient Descent — Finding the best fit by taking small steps downhill.
- Chapter 4: Generalization — Why a model that fits its training data can still fail on new data.
- Chapter 5: Regularization — Keeping models simple with ridge and lasso penalties.
Part II: Classificationabout 1 h
Predicting a category instead of a number. Five different ways to draw the line between yes and no, and how to measure a classifier honestly when one answer is rare.
You need: Part I, especially gradient descent and generalization.
- Chapter 6: Logistic Regression — Predicting a yes or no answer as a probability.
- Chapter 7: Measuring Classifiers — Confusion matrices, precision, recall, and the ROC curve.
- Chapter 8: Nearest Neighbours — Classifying a point by looking at the points around it.
- Chapter 9: Naive Bayes — Turning Bayes' rule into a fast, simple classifier.
- Chapter 10: Support Vector Machines — Separating classes with the widest possible margin.
Part III: Trees and Ensembles
Models built from simple yes-or-no questions, and what happens when hundreds of them vote. These are the models that win most often on tables of data.
You need: Part I and the chapter on measuring classifiers.
- Chapter 11: Decision Trees (being written)
- Chapter 12: Random Forests (being written)
- Chapter 13: Boosting (being written)
Part IV: Neural Networksabout 2 h
A neural network built from nothing, one piece per chapter, until it recognises pictures of clothing. Every chapter comes with a short Python file that runs on its own.
You need: Chapters 1 to 4 and 6, and the toolkit chapters on vectors and derivatives.
- Chapter 14: A Single Neuron — Inputs, weights, and a bias: the smallest piece of a network.
- Chapter 15: Layers and Activations — Stacking neurons, and why they need to bend.
- Chapter 16: Scoring a Classifier — Softmax and cross-entropy: turning outputs into a loss.
- Chapter 17: Backpropagation — The chain rule, applied backward through a network.
- Chapter 18: Optimizers — Momentum, RMSProp, and Adam: smarter ways to step.
- Chapter 19: Keeping Networks Honest — Weight penalties and dropout against overfitting.
- Chapter 20: One Network, Many Jobs — Swapping the output layer for different tasks.
- Chapter 21: A Real Dataset — Training, evaluating, saving, and using a network on images.
- Chapter 22: Convolutional Networks (being written)
- Chapter 23: Sequences and Attention (being written)
Part V: Finding Structure
Learning without answers to learn from. Grouping similar things, squeezing many features into a few, and describing data as a blend of simple shapes.
You need: Part I and the toolkit chapters on vectors and probability.
- Chapter 24: Clustering with k-Means (being written)
- Chapter 25: Principal Component Analysis (being written)
- Chapter 26: Mixture Models and EM (being written)
Part VI: Doing It for Real
The work around the model, which is most of the work. Getting data ready, running a project from the first question to the final check, and where to go after this book.
You need: Parts I and II.
- Chapter 27: Preparing Data (being written)
- Chapter 28: An End-to-End Project (being written)
- Chapter 29: Where to Go Next (being written)
Chapters marked "being written" are not published yet. The changelog lists each one as it arrives.
Common questions
- How much mathematics do I need to learn machine learning?
- School algebra is enough to start. The book's three toolkit chapters teach the vectors, derivatives and probability the later chapters use, with pictures before formulas, and each chapter says which of them it needs.
- Do I need to know how to code?
- No, not to follow the ideas: every idea is shown with a figure you can use in the browser. To build things yourself, some Python helps. The neural network chapters each come with a short NumPy file that runs on its own.
- How long does it take?
- The 21 published chapters take about 6 hours to read, plus time for the exercises. A chapter takes 12 to 20 minutes, so one a day gets you through in about a month.
- Where does deep learning fit in?
- Deep learning means neural networks with many layers. Part IV builds a neural network from nothing, one piece per chapter: neurons, activations, loss, backpropagation, optimizers and regularization, until it recognises photographs of clothing. Read Part I first, because training a network is the same idea as fitting a line, at a larger scale.
- Is it really free?
- Yes. Every chapter, figure and exercise is free to read with no sign-up, and your progress stays in your own browser.