Machine Learning · Insper
The ML Landscape
Fundamental approach
The kinds of learning, the project loop, and what it means for a model to generalize
The path of this part
- Kinds of learningsupervised, unsupervised, reinforcement: by the feedback
- The project loopframe, get data, prepare, train, evaluate, deploy: a loop
- Generalizationtraining and new data; underfitting and overfitting
Each stage answers one question: which kind of learning, by its feedback? → which steps does a real project take? → what makes a model good on data it has never seen?
Stage 1 · which kind of learning, by its feedback?
Learning paradigms: by the feedback
Machine learning (ML) problems are classified by the kind of feedback the learner gets.
Predict. Three situations: (a) past e-mails, each marked spam or not; (b) a pile of customer records, no marks at all; (c) a program that plays a game and only learns at the end whether it won. What feedback does each one have?
Supervised learning: inputs and the answers
The data contains inputs \(x\) and the desired outputs \(y\) (labels). Goal: learn a function \(f\) with \(f(x) \approx y\) on new data.
regression
\(y\) is continuous: house prices, energy demand, a patient's length of stay
classification
\(y\) is categorical: spam or not, benign or malignant tumor, which digit is in the image
The type of \(y\) names the task, not the algorithm: a number is regression, a category is classification.
Unsupervised learning: only the inputs
No labels. The goal is to discover structure.
clustering
group similar observations, e.g. customer segments
dimensionality reduction
compress many features into a few informative ones: PCA (principal component analysis), t-SNE, UMAP
topic modeling
discover themes in a collection of documents (BERTopic)
Reinforcement learning, and the mixtures
- An agent acts in an environment, receives rewards and learns a policy that maximizes long-term reward: game-playing systems (AlphaGo), robotic control.
- Out of scope for this course, but you should recognize it on the map.
semi-supervised
few labels, many unlabeled examples
self-supervised
labels manufactured from the data itself: how foundation models are pre-trained
weak supervision
noisy, programmatic labels
Stage 2 · which steps does a real project take?
The ML workflow
A model is a small part of a larger, iterative process. The course is organized around this loop.
Two practical truths about the loop
most of the work is in steps 2–3
practitioners routinely report spending most of their time understanding and preparing data, not fitting models
the loop never ends
deployed models decay as the world changes (drift); monitoring and retraining are part of the job
Step 1, frame the problem, looks the easiest and is where a project is most often doomed: the advanced approach gives it its own section.
Stage 3 · what makes a model good on data it has never seen?
Generalization: the central problem
Predict. A model gets every training example right: it has memorized them. Is it a good model?
It can still be useless. What matters is performance on data it has never seen.
underfitting
too simple to capture the pattern: poor even on the training data
overfitting
captures noise as if it were signal: excellent on training, poor on new data
Three models, by eye
15 training points (orange) around a curve plus noise; 1,000 new points (blue) the models never see. Error: MSE (mean squared error), the average squared vertical distance. Predict: rank degrees 1, 3, 12 by training error. Same order on new points?
Training error: 0.208 → 0.036 → 0.004, always falling. Error on new points: 0.435 → 0.119 → 92.010. The two rankings disagree, and only the second describes the model once deployed.
Simulator: underfitting and overfitting
Predict. As the degree goes from 1 to 15, what happens to the training error? And to the test error? Then press more data.
The golden rule
- In the lab and the simulator, "new points" come from a generator we wrote: we can draw the future at will.
- A real project has no such generator. The only stand-in for the future is data you set aside and never train on.
- Train/test splits, cross-validation, regularization, the bias–variance trade-off: all exist to manage this tension.
The golden rule. Never evaluate a model on data it was trained on. Test data must simulate the future: unseen, untouched, used once.
Summary
- Paradigms by feedback: supervised (labels), unsupervised (structure), reinforcement (rewards).
- In supervised learning the type of \(y\) names the task: regression or classification.
- The workflow is a loop, and most of the work is in the data.
- Read two errors, never one: both high is underfitting; training low and new-data high is overfitting.
- Only data the model never saw can judge it: never evaluate on the training data.
| what you see | what is happening |
| both errors high and close | underfitting: too simple |
| training tiny, new data much larger | overfitting: it memorized the noise |
| a deployed model slowly getting worse | drift: the world changed |
Fundamental lab · about 30 min, in pairs
The shape of the error, steps 1 to 4
- A world you control: 15 training points around a curve, and 1,000 new points from the same process.
- Polynomials of growing degree, then a model that only memorizes: watch the training error and the error on new points.
- The code is on the lesson page: paste each block into a blank Colab notebook, in order. Nothing to install.
- At every step, answer the Predict before running.
- Simulations: more data (step 3) and nothing to learn (step 4).
Pace: steps 1 and 2 in 8 min; step 3 and the first simulation in 10 min; step 4 and the second in 12 min.