Machine learning, from basics to mastery
92 short, animated lessons in 15 chapters. Free, no maths background needed.
Chapter 1: Foundations
What machine learning is, and how data feeds it.
- What is machine learning?: A normal program is a recipe. You write the rules, the computer applies them to data and produces answers.
- Data, features and labels: Most ML starts with a table. Each row is one example (here, one house). Each column is one thing we measured…
- Training and test sets: Here are 20 labeled examples. If we train on all of them, we have nothing left to check whether the model…
- Types of learning: Every example comes with the right answer (its color here). The model learns a rule that separates the…
Chapter 2: Math toolkit
Just enough vectors, calculus and probability to read any model.
- Vectors: A single number, like a temperature or a price, is called a scalar. Picture it as one bar.
- Dot products and matrices: Take two vectors of the same length: a = [2, 1, 3] and b = [1, 2, 1]. The dot product turns them into one…
- Derivatives and slopes: Here is f(x) = x², drawn as a row of bars. The middle bar is x = 0. Lower bars are smaller outputs.
- Probability basics: Flip a coin 10 times: H T H H T T H T H H. Yellow is heads, blue is tails. Each flip is random, but patterns…
- Mean, variance and the normal curve: Eight measurements: 2, 4, 4, 4, 5, 5, 7, 9. Repeated values stack up. Two questions matter: where is the…
Chapter 3: Regression and optimization
Fit a line, measure the error, and walk downhill to the best model.
- Linear regression: Each bar is one house: size along the floor, price as height. Bigger houses tend to cost more, but not…
- Loss functions: We have a line and its residuals. To compare two lines we need one number that sums up how wrong a line is.…
- Gradient descent: Plot the loss for every possible value of a weight w and you get a valley. Training means finding the…
- The learning rate: With lr = 0.1, each step is tiny. After 8 steps the ball has barely moved. Training would take forever.
- Underfitting and overfitting: The bars follow a gentle wave, plus random noise. The noise is not a pattern. It will not repeat on new…
Chapter 4: Classification
Predict categories instead of numbers, and score the results honestly.
- Logistic regression: Some questions have only two answers. Will this student pass? Is this email spam? This kind of problem is…
- Sigmoid and softmax: A model first produces a raw score, which can be any number at all. The sigmoid turns it into a chance…
- Decision boundaries: Each student is now a dot on a map: how long they studied (one direction) and how long they slept (the…
- k-nearest neighbors: Here is our map of students again, plus a new one (yellow) whose result we don’t know yet. The idea behind…
- Naive Bayes: We have 100 old emails, already sorted by a person: 40 spam (coral) and 60 normal (teal). So before reading…
- Support vector machines: A support vector machine picks the line with the most breathing room on both sides, like the middle of the…
- The confusion matrix: We test a spam filter on 20 emails where we know the truth. Each block is an email, colored by the truth…
- Precision, recall and F1: Look only at the emails the model called spam: the left column. 6 really were spam and 3 were false alarms.…
- ROC curves and AUC: The model gives each email a spam score from 0 to 1. Coral balls are real spam, teal are normal. The yellow…
Chapter 5: Generalization
Make models that work on data they have never seen.
- Bias and variance: Train the same kind of model on different samples of data and each version guesses a little differently.…
- Cross-validation: cross-validation cuts the data into equal slices called folds. Here there are 5, shown in different colors.
- L1 and L2 regularization: regularization adds a penalty to the loss: the bigger the weights, the bigger the fee. Now the model only…
- Feature scaling: Lopsided scales turn the error landscape into a long, narrow valley. Gradient descent zigzags across it,…
- Hyperparameter tuning: Some settings aren’t learned from data: you pick them before training, like the learning rate or how deep a…
- Data leakage: One feature, “was given treatment X”, is only known after a doctor diagnosed the disease. The model learned…
Chapter 6: Trees and ensembles
Split data with questions, then combine many models into one.
- Decision trees: A decision tree makes a prediction by asking a series of yes-or-no questions, like the game twenty…
- Entropy and Gini: A tree wants groups that are as “pure” as possible: all one answer. impurity measures how mixed a group is.…
- Bagging: Draw random samples from the data, putting each row back after picking it. Some rows show up twice and…
- Random forests: A random forest is bagging with decision trees, plus one twist: at each question, a tree may only consider a…
- Boosting: Boosting starts with a very simple model, a weak learner: here, a single cut. It gets most points right, but…
- Gradient boosting: Gradient boosting begins with the simplest possible guess for every house: the average price. The dashed…
Chapter 7: Unsupervised learning
Find structure in data that has no labels.
- k-means clustering: Here are 24 customers placed by how they shop. Nobody has told us any groups. Can the computer find natural…
- Hierarchical clustering: Hierarchical clustering starts by treating every point as its own tiny group: six points, six groups.
- DBSCAN: Draw a small circle around each point and count the neighbors inside it. A point with enough neighbors is a…
- Principal component analysis: PCA looks for the direction along which the points are most spread out: the first principal component (red).…
- t-SNE and UMAP: Place the points on a flat map and nudge them over and over: neighbors pull together, strangers push apart.…
- Anomaly detection: Gather lots of everyday data: here, ordinary transactions. Most of it clumps together. The dashed ring marks…
Chapter 8: Neural networks
Stack simple units into networks that learn almost anything.
- The perceptron: A perceptron is the simplest artificial neuron. It takes a few inputs, here three yes/no facts about a…
- Activation functions: An activation function adds a bend. The most popular, relu, is wonderfully simple: negative numbers become…
- Multilayer networks: Put neurons side by side to make a layer, then stack layers. Every neuron in one layer connects to every…
- The forward pass: A forward pass is how a network makes a prediction. It starts with the input: here, two numbers describing a…
- Backpropagation: Run a forward pass, then compare the prediction with the truth. The network said 90% cat, but the photo was…
- Cross-entropy loss: Classifiers output probabilities. To train them we need a loss that judges how much probability went to the…
- Optimizers: SGD, momentum and Adam: With momentum, each step keeps some of the previous one, like a heavy ball rolling downhill. The…
- Weight initialization: Before training, every weight needs a starting value. All zeros won’t work: every neuron would compute the…
- Dropout: With dropout, every training step switches off a random handful of neurons (greyed out). The rest must cope…
- Batch normalization: batch normalization measures the mean and spread of each layer’s outputs for the current batch, then shifts…
Chapter 9: Computer vision
Teach networks to see with convolutions.
- Images as numbers: To a computer, an image is a grid of tiny squares called pixels. This one is just 6 × 6, a little smiley face.
- Convolution: This image is dark on the left and bright on the right. A filter is a small 3 × 3 grid of weights. This one…
- Filters and feature maps: The first layer has many filters, each producing its own feature map. They learn to respond to simple…
- Pooling and stride: Split the map into 2 × 2 blocks (one color each).
- CNN architectures: Most vision networks follow one recipe: repeat “convolution, ReLU, pooling” a few times, then finish with…
- Transfer learning: transfer learning starts from a network someone already trained on a huge photo collection. Its early layers…
Chapter 10: Sequences and text
Models that read words, sounds and time series.
- Tokenization: Splitting on spaces is a start. But English has hundreds of thousands of words, plus names, typos and new…
- Word embeddings: An embedding turns each token into a list of numbers: a point in space. Before training, the points are…
- Recurrent networks: Language comes in order. A recurrent network reads a sentence one word at a time, from left to right, just…
- LSTM and GRU: An lstm adds a separate memory “belt” that runs along the whole sequence. Information can ride on it for a…
Chapter 11: Transformers and LLMs
The architecture behind modern language models.
- Attention: attention lets the word “it” look at every word in the sentence, all at once, and score how relevant each…
- Queries, keys and values: Each token makes three vectors: a query (red: what am I looking for?), a key (blue: what do I contain?) and…
- Multi-head attention: One attention calculation, called one attention head, tends to focus on one kind of relationship. This head…
- Positional encoding: “Dog bites man” is ordinary. “Man bites dog” is news. Same three words, different order, different meaning.
- The transformer block: A transformer is built from identical blocks. Each block starts with attention (purple): every token gathers…
- Pretraining: pretraining starts with an enormous collection of text: books, websites, articles and code, adding up to…
- Fine-tuning and LoRA: After pretraining you have a model that knows a lot about language in general. Now you want it to do your…
- RLHF and preference tuning: A pretrained model can write many possible replies. Some are helpful, some ramble, some are wrong. For one…
- Embeddings and vector search: Run every document, photo or product description through an embedding model. Each becomes a point. Similar…
- Retrieval-augmented generation: rag first runs a vector search over your documents to find the few passages most relevant to the question.
Chapter 12: Generative models
Models that create new images, audio and text.
- Autoencoders: An autoencoder has two halves. The encoder (blue) squeezes an image through narrower and narrower layers.
- Variational autoencoders: A plain autoencoder maps each image to one exact point, and the space between points can be meaningless. A…
- GANs: A GAN has two networks. The generator turns random noise into fake images. The discriminator looks at an…
- Diffusion models: Take a real image and add a little random noise. Then a little more, and more, until it’s pure static. This…
Chapter 13: Reinforcement learning
Learn by acting and collecting rewards.
- Agents and rewards: Reinforcement learning has an agent (the learner) inside an environment (the world). The agent observes its…
- Markov decision processes: A markov decision process writes a decision problem down precisely. First, the states. A smart thermostat’s…
- Q-learning: Q-learning keeps a q-value for every state and action: “how much total reward do I expect if I do this…
- Policy gradients: Instead of a Q-table, a policy gradient method learns the policy directly: a network that gives a…
Chapter 14: ML in practice
Ship models that keep working in the real world.
- Data pipelines: A data pipeline runs the same cleaning steps every time: drop duplicates, fix types, fill or remove missing…
- Experiment tracking: experiment tracking records, for every run, the settings, the data version, the results and the saved model.…
- Deploying models: Training ends with a file full of weights. Nobody benefits until it’s put somewhere that can answer real…
- Monitoring and drift: A model learns from data collected at one point in time: here, the typical shopping basket. As long as new…
- Fairness and responsible ML: A model can look accurate overall while treating groups of people very differently. fairness work starts by…
Chapter 15: Story: judging an AI with people
Follow Maya’s team as they launch a chatbot and learn every way people evaluate AI.
- Episode 1: Launch week: Automatic scores compare words. They can’t tell whether an answer is truly helpful, correct, kind or safe.…
- Episode 2: Give it a score: A rating scale turns opinions into numbers you can track. Pip averages 3.6. But look at the spread too: a…
- Episode 3: Which version is better?: Instead of scoring answers one at a time, show both versions’ answers to the same question side by side and…
- Episode 4: Two raters, two verdicts: Both raters label the same answers: teal is safe, coral is unsafe. Top row is Priya, bottom row Sam. They…
- Episode 5: Real customers decide: In an a/b test, each incoming customer is randomly sent to old Pip or new Pip. Random assignment makes the…
- Episode 6: Paid to break it: red-teaming means attacking on purpose: trick instructions, false premises, requests for other customers’…
- Episode 7: Too many answers to read: Leo sets up an ai judge: a strong AI model given Maya’s scoring guide. It reads every conversation and gives…
- Episode 8: The evaluation ladder: Lower rungs are fast and cheap, so they run constantly. Higher rungs are slower and costlier but closer to…
Hands-on projects
- Your first ML model: an iris flower classifier (Beginner, 20 min)
- Gradient descent from scratch (Beginner, 30 min)
- House price predictor (Beginner, 30 min)
- Spam filter with Naive Bayes (Beginner, 30 min)
- A screening classifier that doesn’t miss cases (Intermediate, 35 min)
- Loan decisions with trees and forests (Intermediate, 35 min)
- Find customer segments with k-means (Intermediate, 30 min)
- A neural network that reads handwriting (Intermediate, 35 min)
- Build a mini search engine (the R in RAG) (Intermediate, 30 min)
- Spot fraud with anomaly detection (Intermediate, 25 min)
- Human evaluation toolkit (Intermediate, 30 min)
- Serve your model as a web API (Advanced, 40 min)