Loading
Module 3 of 12

How Machines Learn From Data

About 8 minute read

"Machine learning" sounds mysterious, but the core idea is simple: instead of a programmer writing explicit rules ("if the email contains the word 'lottery', mark it as spam"), you show the computer many examples and let it work out the pattern itself.

Features and labels

Every machine learning problem starts by turning real-world things into numbers — the vectors from Module 2. Each measurable property is called a feature. For a house-price model, features might be square footage, number of bedrooms, and neighborhood. For a spam filter, features might be word counts, sender reputation, and number of links.

If you're trying to predict something, that target is called the label (or "target"). The house's actual sale price is the label. "Spam" or "not spam" is the label. A dataset used to train a model is simply a big table: one row per example, one column per feature, and (usually) one column for the label.

Training data vs. test data

You never let a model learn from all your data and then evaluate it on the same data — that's like grading a student using the exact questions they memorized the answers to. Instead, data is typically split:

  • Training data (usually ~70–80%) — what the model actually learns from.
  • Test data (the rest) — held back and only used afterward, to check how well the model performs on examples it has never seen.

A model that does great on training data but poorly on test data has overfit — it memorized quirks of the training examples instead of learning the underlying pattern. A model that does poorly on both has underfit — it's too simple to capture the pattern at all. Good generalization, performing well on new unseen data, is the entire goal.

Garbage in, garbage out. A model can only be as good as its data. If your training examples are biased, incomplete, or mislabeled, the model will confidently learn — and repeat — those flaws. We'll come back to this in Module 11.

The learning loop, at a glance

Nearly every supervised learning technique in this guide (linear regression, k-Nearest Neighbors, neural networks) follows the same shape:

  1. Collect examples with known answers (features + labels).
  2. Choose a model — a mathematical function with adjustable numbers ("parameters") inside it.
  3. Measure how wrong the model currently is (its "loss" or "error").
  4. Adjust the parameters to reduce that error.
  5. Repeat steps 3–4 many times, then check performance on held-out test data.

Module 5 walks through this loop concretely with linear regression, and Module 8 shows the general algorithm — gradient descent — that does step 4 for almost every model, including deep neural networks.

Check your understanding
1. In a dataset for predicting house prices, "square footage" would be a:
2. Why do we hold out a separate test set instead of evaluating on training data?
3. A model that scores 99% on training data but 60% on test data is most likely:
Did you like the lesson? 😆👍
Consider a donation to support our work: