Why does your phone unlock when it sees your face, your email auto-sort spam, and Netflix know you'd love that obscure documentary? They're all the same trick: a machine learned a pattern from examples instead of being told explicit rules. By the end of this lesson, you'll be able to look at any real-world AI feature — Tesla autopilot, ChatGPT, Shazam, Google Translate — and instantly identify which of three flavors of machine learning is running under the hood, plus exactly why each one was the right choice.
Learning Objectives
After this lesson, you will be able to:
Tell the difference between the three types of ML — supervised (learning from labeled examples), unsupervised (finding patterns with no labels), and reinforcement (learning by trial and error)
Walk through the full training loop from start to finish and understand what each step does
Understand the bias-variance tradeoff — why a model can ace the practice test but bomb the real exam
Choose the right ML paradigm for a given problem — and recognize when labels, rewards, or neither are the right signal
Distinguish between a loss function, a metric, and a hyperparameter — three concepts that beginners often confuse
Try it: Switch between algorithms and watch the decision boundary changeInteractive
Loading visualization...
Interactive Lab
Toggle between algorithms (logistic regression, KNN, SVM) on the same dataset and see how each paradigm shapes the boundary differently.
Don't worry if "bias-variance tradeoff" sounds scary — it is really just the balance between a model that is too simple (underfitting) and one that memorized the answers (overfitting). It clicks once you see the training curves!
Supervised learning is the most common paradigm in industry. You have a dataset of input-output pairs, and the goal is to learn a function that maps inputs to outputs.
f:X→Ygiven {(x1,y1),(x2,y2),…,(xn,yn)}
Try it! Open the Python REPL and type these lines yourself. Train a quick classifier: from sklearn.datasets import load_iris; from sklearn.tree import DecisionTreeClassifier; X, y = load_iris(return_X_y=True); m = DecisionTreeClassifier().fit(X, y); print(f"Accuracy: {m.score(X, y):.0%}") — you just trained your first ML model!
The output is a category. Spam or not spam. Cat or dog. Malignant or benign. The model draws decision boundaries that separate classes in feature space.
The output is a continuous number. House price. Temperature tomorrow. Stock return. The model fits a curve through the data points.
What Do You Think?
A hospital wants to predict patient readmission risk as a percentage (0-100%). Is this classification or regression?
The answer is regression -- the output is a continuous percentage. However, if you threshold it (above 50% = high risk, below = low risk), you turn it into a classification problem. Many real-world systems combine both: predict a continuous score, then threshold for decisions.
Quick check
You're shown a labeled dataset of leaf images with species names. You train a model to predict the species of new leaves. Which paradigm is this?
In reinforcement learning (RL), an agent takes actions in an environment and receives rewards. The goal is to learn a policy -- a strategy that maximizes cumulative reward over time.
RL is behind AlphaGo, robotics, self-driving cars, and the RLHF (Reinforcement Learning from Human Feedback) that makes ChatGPT helpful rather than harmful.
A mathematical measure of "how wrong is the model right now?" The loss function translates the abstract goal ("classify emails correctly") into a concrete number the optimizer can minimize.
Adjust hyperparameters, try different models, engineer better features. Repeat until performance is satisfactory.
θ^=argθminn1i=1∑nL(yi,fθ(xi))
Step through the full sklearn workflow end-to-end on the classic Iris dataset. Every real ML pipeline you'll ever write follows this exact six-step shape — load, split, preprocess, train, evaluate, predict. Pay close attention to where fit_transform is called vs. where only transform is called: that one distinction is the single most common source of silent data leakage.
Loading visualization...
Quick check
In the workflow above, why call scaler.fit_transform(X_tr) but only scaler.transform(X_te)?
Quick check
A team built a fraud model and got 99.7% test accuracy. They then realized they had imputed missing values using the median of the ENTIRE dataset (train + test) before splitting. What did they leak?
Bias is the error from incorrect assumptions in the model. A linear model applied to non-linear data will always have high bias -- no matter how much data you give it, it will never learn the true curved relationship. Bias measures how far off the model's average prediction is from the truth.
Variance is the error from sensitivity to fluctuations in the training data. If you retrain a model on a slightly different dataset and the predictions change wildly, the model has high variance. Complex models (deep trees, high-degree polynomials) are prone to high variance -- they latch onto noise.
Let us walk through the training loop with concrete numbers. You have 5 patients with their glucose level (mg/dL) and a binary label (1 = diabetic, 0 = not):
Patient
Glucose
Diabetic?
1
85
0
2
110
0
3
140
1
4
165
1
5
200
1
Step 1 — Choose a model: linear function score = w * glucose + b.
Step 2 — Start with random weights:w = 0.01, b = -1.5. Predictions: 85 -> -0.65, 110 -> -0.4, 140 -> -0.1, 165 -> 0.15, 200 -> 0.5. Threshold at 0: predicts . Two mistakes on patients 3 and 4.
Step 3 — Measure loss: average squared error vs. labels ~ 0.30.
Step 4 — Adjust weights: the optimizer notices patients 3 and 4 need a higher score, so it nudges w up to 0.015 and b down to -2.0.
Step 5 — Re-predict: 140 -> 0.1, 165 -> 0.475 — patients 3 and 4 now cross the threshold. All 5 correct. Loss drops to ~0.05.
Step 6 — Test on a new patient: glucose = 130 -> score = -0.05 -> predict "not diabetic." A held-out 6th patient with glucose 130 and true label 0 confirms the model generalized.
That is the full training loop in 6 numerical steps. Every ML model — from logistic regression to GPT — repeats this same loop, just with millions of weights instead of two.
Tests · Observe that train error monotonically decreases with degree. Identify the degree where test error is minimized. Explain why the gap between train and test error grows with complexity.
Three paradigms cover all ML. Supervised learning maps inputs to outputs with labeled data, unsupervised learning discovers structure without labels, and reinforcement learning optimizes strategies through reward signals
The bias-variance tradeoff is the central tension. Too simple a model underfits (high bias, misses patterns), too complex a model overfits (high variance, memorizes noise), and the art is finding the sweet spot
Always evaluate on held-out data. A model that memorizes training data gets 100% training accuracy but may be useless on new data; generalization performance is the only metric that matters
Start simple, increase complexity only when needed. A well-tuned logistic regression often beats a poorly tuned neural network; Occam's Razor applies to model selection
A model has low training error but high test error. What is the most likely problem?
Now that you understand the three ML paradigms and the bias-variance tradeoff, let us build your first model. Next up: Linear & Polynomial Regression -- fitting lines and curves to data.