AI→ML
Roadmap  ›  Part I · The AI Landscape  ›  Module 0 · Orientation
Lesson 04 · Foundations

What Is Machine Learning?

We've located Machine Learning on the map. Now we step inside it. What does it actually mean for a program to "learn," what kinds of learning exist, and what is the repeatable workflow that every algorithm in the rest of this course plugs into?

Reading: ~30 min Prerequisites: Lessons 1–3 Code: a tiny bit of pseudocode — the machinery starts here
Why this is the hinge lesson of the whole course

Lessons 1–3 were the map. This is the machine. Every remaining lesson — Linear Regression, k-NN, Decision Trees, k-Means, all of it — is a specific instance of the two ideas you'll meet here: a type of learning (what experience the model gets) and the ML workflow (the pipeline from raw data to a trusted model). Get this lesson solid and every later algorithm becomes "fill in the blanks of a template you already know." By the end you'll be able to take any new problem and say what type of ML it is and what the end-to-end steps to solve it would be.

One example we'll carry through the whole lesson

Abstractions blur; a running example keeps us honest. Throughout this lesson we'll use one small, concrete dataset — predicting a house's sale price from a few of its properties — and revisit it at every stage. Here are five rows of it:

Size (m²)BedroomsAge (yrs)NeighborhoodSale price (€)
60230East180,000
85312Center295,000
12045Center430,000
45140West132,000
10038East350,000

Keep this table in mind. We'll point at its columns to define every term below.

What this lesson delivers

1 · What "learning" means for a machine

The word "learning" invites mysticism, so let's kill the mysticism immediately. In Lesson 1 we met the definition that strips it bare — worth restating because it is the spine of everything below:

Mitchell's definition (1997)
A computer program learns from experience E with respect to task T and performance measure P, if its performance at T, measured by P, improves with E.

No consciousness, no understanding — just measurable improvement on a task as it sees more data. "Learning" is fitting a program to data so that a number goes up (or an error goes down).

The triple, filled in for our house example

Mitchell's definition isn't decoration — you can instantiate it right now:

If the average error shrinks as we feed it more past sales, the program is learning. That's the whole claim, made measurable.

Contrast the two paradigms directly, because the inversion is the entire point of the field:

Classical programmingMachine Learning
You writeThe rules (the algorithm)A learning procedure + example data
InputsData + rulesData + desired answers
OutputAnswersThe rules (a trained model)
When to useYou can state the rulesYou can't state the rules, but you have examples
Engineer's translation — on the house problem

The classical approach would have you write the pricing formula yourself: maybe price = 3000 × size + 10000 × bedrooms − 500 × age. But where did those coefficients come from? You'd be guessing. The ML approach refuses to guess: you hand it the table of past sales (inputs and the prices) and it discovers the coefficients that best reproduce them. In classical programming, rules + data → answers. In ML you flip two boxes: data + answers → rules. Training is program synthesis by numerical optimization.

That phrase — generalizes to new inputs — is the whole game, and it deserves its own callout because it's the difference between learning and memorizing.

The one thing ML is really trying to do: generalize

Any program can memorize a lookup table of the training examples and score perfectly on them. Example: a model that simply stores "60 m², East → €180,000" answers perfectly for that exact house and is useless the moment a 62 m² house in the East shows up — a value it has never seen. That's memorizing, not learning. The goal of ML is generalization: performing well on data it has never seen. Everything hard about the field (overfitting, validation, regularization — Parts III and V) exists to serve this one goal. Keep asking, of every technique: "how does this help the model generalize rather than memorize?"

2 · The vocabulary you'll use in every remaining lesson

Before the types and the workflow, lock down five words. Every algorithm reuses them, so we define them once — and point each one at a column of the house table.

1
Features (inputs, X) — the measured properties you feed the model, one row per example, one column per property. In our table: size, bedrooms, age, neighborhood — the four leftmost columns. Choosing and shaping these is feature engineering (Lesson 27).
2
Label / target (output, y) — the answer you want to predict. Here, the sale price column. Present in supervised learning; absent in unsupervised.
3
Model — the parameterized function f that maps features to a prediction: ŷ = f(X). Choosing a model means choosing the form of f. For houses we might pick a line: price = w₁·size + w₂·bedrooms + w₃·age + b.
4
Parameters (weights) — the tunable numbers inside f that training adjusts. In that formula, w₁, w₂, w₃ and b. Learning is finding good values for them — e.g. discovering w₁ ≈ 3,100 €/m².
5
Training — the procedure that searches for parameter values which minimize error on the data, measured by a loss function (Lesson 6) and driven by optimization (Lesson 7).
Worked example: features, prediction, and error in numbers

Suppose training landed on the model price = 3,100·size + 8,000·bedrooms − 600·age + 5,000. Take the third house in our table (120 m², 4 bedrooms, 5 years old):

ŷ = 3,100·(120) + 8,000·(4) − 600·(5) + 5,000 = 372,000 + 32,000 − 3,000 + 5,000 = €406,000

The actual price was €430,000, so this prediction is off by €24,000. That gap — the error — is exactly what training tries to make small across all rows at once. Every algorithm in this course is, at heart, a smarter way of shrinking that gap.

The whole of supervised ML in one line

Strip away the specifics and every supervised algorithm is doing this:

find parameters of f such that f(X) ≈ y on training data — and still ≈ y on unseen data.

The models differ only in the shape of f and how we search for its parameters. That's it. That's the course.

3 · The types of learning

Machine Learning problems divide by what kind of experience the system learns from — the E in Mitchell's triple. There are three canonical types (plus one important in-between), and each answers a different question. We'll give each a concrete example built from the same real-estate world, so the differences are unmistakable.

A
Supervised learning — the data has inputs and correct answers (labels). Question: "Given labeled examples, what's the answer for this new case?" Example: our house table — features plus the known sale price. The model learns to price a new listing. Parts III & IV — the bulk of this course.
B
Unsupervised learning — the data has inputs only, no answers. Question: "What natural structure is in this data?" Example: the same houses with the price column removed — group them into "types of property" (small old flats, large new family homes…) that nobody labeled in advance. Part VII — k-Means, PCA.
C
Reinforcement learning — an agent acts in an environment and gets rewards; it learns a strategy by trial and error. Question: "What sequence of actions maximizes long-term reward?" Example: an agent that repeatedly sets a listing price, observes whether the house sells and for how much, and adjusts its pricing strategy over many sales. Context only — out of scope.
D
Semi-supervised / self-supervised — a little labeled data plus a lot of unlabeled data, or labels manufactured from the data itself. Question: "How do I learn when labels are scarce or expensive?" Example: 200 houses with verified sale prices and 50,000 listings with none — use the huge unlabeled set to learn structure, the small labeled set to anchor prices. The engine behind modern LLMs, mentioned for completeness.
A one-question decision tree for the type

Do you have labeled answers to learn from? Yes → supervised. No, just raw data to explore → unsupervised. No labels, but an environment that pays out rewards for actions → reinforcement. The single most common beginner mistake is trying to force an unsupervised problem (no labels) into a supervised algorithm. Identify the type first; it determines every downstream choice.

The supervised split: regression vs classification

Because supervised learning is most of the course, it gets its own subdivision — decided entirely by what kind of thing the label is.

RegressionClassification
Label is…a continuous numbera category / class
Answers…"how much / how many?""which one / is it?"
House-data versionpredict the sale price (€430,000)predict "will it sell within 30 days?" (yes / no)
Other examplestemperature, demand, salaryspam/not, disease type, digit 0–9
Course homePart III (Lessons 10–13)Part IV (Lessons 14–18)
Watch the trap: the label's type, not the feature's

Example: "predict the number of stars (1–5) a review gets." It looks numeric, but the answer is one of five discrete categories, so it's usually treated as classification (or its cousin, ordinal). Contrast: "predict a house's price" is genuinely continuous — €406,001 and €406,002 are both valid and meaningfully close — so it's regression. Always ask what the output is, and whether the distances between output values are meaningful.

4 · The Machine Learning workflow

Here is the payoff of the lesson: the repeatable pipeline that turns a business problem into a trustworthy model. Every project follows this loop, and every remaining lesson is a deep dive into one stage. We'll state each step and walk it on a concrete brief:

The brief we'll solve

A real-estate agency wants a tool that suggests a listing price for a new house from its size, bedrooms, age, and neighborhood. They have a spreadsheet of 5,000 past sales. Let's walk the eight steps on exactly this.

1
Frame the problem — Our brief: T = predict sale price; P = average euro error on unseen houses; E = the 5,000-row spreadsheet. Label is a continuous number → supervised regression. This decision alone rules out classification algorithms and metrics.
2
Collect & explore data — Our brief: load the spreadsheet, plot price vs size, and notice three rows list a price of €0 (data-entry errors) and some ages are blank. (Lesson 8 — Pandas/Matplotlib.)
3
Prepare data & engineer features — Our brief: drop the €0 rows, fill missing ages with the median, turn "Neighborhood" text into numeric columns (one-hot: is_East, is_West, is_Center), and add a derived feature price-relevant like rooms-per-m². Usually the majority of the real work. (Lessons 12, 27.)
4
Split the data — Our brief: randomly set aside 1,000 houses as a test set (and some for validation) before training, so we measure on sales the model never saw. Peeking here causes data leakage. (Lesson 19.)
5
Choose a model & train it — Our brief: start with Linear Regression, fit its weights on the 4,000 training houses by minimizing squared euro error. (Lessons 5–7, and every algorithm lesson.)
6
Evaluate — Our brief: on the held-out 1,000 houses, the average error is €31,000. Is that good enough for the agency? Compare against a dumb baseline ("always predict the average price") to know. (Lessons 13, 20.)
7
Tune & select — Our brief: try polynomial features and a Decision Tree; the tree lowers error to €26,000. Adjust hyperparameters, compare, and loop back if needed. (Lesson 21.)
8
Deploy & monitor — Our brief: ship the pricing tool, then watch it — if the market heats up next year, yesterday's model will systematically under-price and errors will creep up, sending you back to step 2 with fresh sales.
It's a loop, not a line

The numbering suggests a straight march, but real ML is a cycle. In our brief, the disappointing €31,000 error at step 6 pushed us back to step 3 (better features) and step 5 (a different model). Drift in production (step 8) will push us back to step 2. Notice how few of the eight steps are "train the model." The algorithm is one box; the discipline around it is the other seven — and that discipline is what separates a trustworthy tool from a demo.

Where each Part of this course lives on the loop

Parts II (concepts & tools) and the algorithm Parts III/IV/VI/VII all deepen steps 3–5 (prepare, choose, train). Part V (evaluation) is steps 4, 6, 7. Part VIII (practical ML & capstone) walks the entire loop end-to-end — much like the house brief above. You now have the skeleton every later lesson hangs on.

The shape of "training," in eight lines

No real algorithm yet — but so the word "training" isn't abstract, here is the pattern almost every supervised learner in this course will follow. Read it as the machine repeatedly re-pricing our 4,000 houses and nudging its weights toward the true prices:

# The universal training loop, in spirit
model = init_parameters()              # start with a guess, e.g. all weights = 0
for step in range(num_steps):
    predictions = model.predict(X_train)          # its price for every house right now
    error       = loss(predictions, y_train)      # avg gap vs true prices (Lesson 6)
    gradient    = d_loss_d_parameters(error)       # which way reduces the gap (Lesson 7)
    model       = update(model, gradient)          # nudge each weight that way
# repeat until the error stops improving → the model has "learned"

Predict, measure error, adjust, repeat. That is training. Concretely: step 0 predicts €0 for every house (error huge); after many iterations w₁ has climbed toward ~€3,100/m² and the error has fallen to its minimum. Loss functions (Lesson 6) define "error," and optimization (Lesson 7) defines "which way to adjust" — which is exactly why those two lessons come next.

5 · Limitations — what to keep honest about

Guardrails to carry into every project

How this connects to the next lesson

Bridge to Lesson 5 — and the end of Module 0

This closes Part I: you have the map (Lessons 1–3) and now the machine's blueprint — types of learning and the eight-step workflow, walked on a real brief. Part II zooms into the conceptual core those steps assume. Lesson 5 — Model, Parameters, and Error takes the vocabulary you just met — the house model, its weights, the €24,000 gap — and makes it rigorous, so that when Lesson 6 defines loss and Lesson 7 defines optimization, the universal training loop above turns from pseudocode into something you can actually build. The rest of the course is filling in that loop, one algorithm at a time.

Exercises & reflection

Still calibration, not code — but now the answers should feel like the start of real ML thinking.

Exercise 1 · Name the type

Classify each as supervised (regression or classification), unsupervised, or reinforcement:

  1. Predict tomorrow's electricity demand in megawatts.
  2. Group a store's customers into segments with no predefined categories.
  3. Decide if a transaction is fraudulent, given past labeled transactions.
  4. Teach a robot to walk by rewarding forward motion.
Show discussion

(1) Supervised — regression (continuous number). (2) Unsupervised — clustering, no labels given. (3) Supervised — classification (fraud/not, with labels). (4) Reinforcement — reward from acting in an environment. If you paused on (1) vs (3): the deciding factor is the label type — a number vs a category.

Exercise 2 · Predict and score by hand

Using the model price = 3,100·size + 8,000·bedrooms − 600·age + 5,000, compute the prediction and the error for the second house in our table (85 m², 3 bedrooms, 12 years old, actual €295,000).

Show solution

ŷ = 3,100·85 + 8,000·3 − 600·12 + 5,000 = 263,500 + 24,000 − 7,200 + 5,000 = €285,300. Actual is €295,000, so the error is €9,700 (the model under-predicts). Notice it's a smaller gap than the €24,000 we saw on house 3 — training minimizes these gaps across all rows at once, so no single house is perfect.

Exercise 3 · Walk the workflow

Pick a supervised problem (e.g. "predict which trial users will convert to paid"). Write one concrete sentence for each of the eight workflow steps as they'd apply — mirroring the house brief. Where would you most fear data leakage, and which step guards against it?

Exercise 4 · Memorize vs generalize

Explain, in two sentences, why our house model scoring €0 error on the 4,000 training houses might be worse than one scoring €20,000 on them. Use the words "memorize" and "unseen." (You've just previewed overfitting — Lesson 13.)

One-paragraph summary to lock it in

Machine Learning is program synthesis by optimization: instead of writing the pricing rule, you supply past sales (features and prices) and let training fit a model's parameters so that f(X) ≈ y — and, crucially, still holds on houses it has never seen (generalization). Problems divide by the experience available — supervised (labeled prices), unsupervised (prices removed, find groups), reinforcement (rewarded actions) — and supervised further splits into regression (predict the price) and classification (predict "sells in 30 days?"). Every project runs the same eight-step loop from framing to monitoring, of which "train the model" is a single step; the other seven are the discipline that makes the model trustworthy. That loop is the scaffold on which the entire rest of this course is built.