Machine Learning Basics: Data, Features and Labels
Learn how a model is trained from examples, what features and labels are, why test data matters, and the three main types of machine learning.
Welcome back!
Step 1 of 14Learn
Teaching by example
Think about how a child learns what a dog is. Nobody hands them a definition with rules about ears, tails and fur. Parents point: dog, dog, cat, dog, horse. After enough examples, the child recognizes dogs they have never seen, including cartoon dogs and dogs in costumes. Sometimes they call a fox a dog, and someone corrects them.
Machine learning works in a similar spirit. Instead of programming the answer, you give an algorithm many examples and let it adjust itself until its outputs match the examples well. The result of that process is called a model: a mathematical function with internal numbers, called parameters, that were tuned during training.
Here is the vocabulary you need, using house prices as the example:
- An example (or data point) is one house.
- Features are the measurable inputs that describe it: square footage, number of bedrooms, neighborhood, age of the building.
- The label is the correct answer you want the model to learn to predict: the price the house actually sold for.
- Training means showing the algorithm thousands of houses with their features and labels and letting it adjust its parameters to reduce its errors.
- Inference or prediction means using the trained model on a new house, where you know the features but not the price.
The model never sees a rule like each extra bedroom adds $25,000. It discovers relationships like that, and many subtler ones, from the data itself. That is both the power and the risk: it learns whatever patterns are in the data, including the ones you didn't intend.
Step 2 of 14Practice · Match the pairs
A model predicts whether a credit card transaction is fraudulent. Match each term to its role in this example.
Tap an answer, then tap the place where it belongs (or drag it there).
- Feature
- Label
- Training data
- Inference
Step 3 of 14Practice · Diagram
The machine learning workflow
Which stage protects you from fooling yourself with a model that only memorized?
Tap the shape that answers the question, then press Check.
- Collect labeled examples
Past cases where you know the right answer.
- Choose features
Pick the measurable inputs the model will look at.
- Split the data
Hold some data back so you can test fairly later.
- Train the model
The algorithm adjusts itself to fit the training examples.
- Test on unseen data
Measure performance on the held-back test set.
- Deploy and monitor
Use the model on new cases (inference) and watch for drift.
Step 4 of 14Learn
Why we hide some of the data
Suppose you study for a test by memorizing the answers to last year's exam, and then the teacher gives you last year's exam. You score 100%, but that score says nothing about whether you understand the subject.
Machine learning has the same trap. A flexible model can simply memorize its training examples. So the standard practice is to split your data before training:
- The training set, often around 70–80% of the data, is what the model learns from.
- The test set, the remaining 20–30%, is locked away and used only at the end to measure performance on examples the model has never seen.
Often a third slice, the validation set, is used during development to compare model versions and settings, so the test set stays truly untouched.
The goal of machine learning is not to do well on the training data. It is to generalize: to perform well on new data from the real world. The test set is your best estimate of that.
A related danger is data leakage, when information about the answer sneaks into the features. A famous style of mistake: a model trained to detect a disease from hospital scans learns that scans taken with a particular portable machine are more often positive, because sicker patients were scanned in bed. It scores brilliantly on test data from the same hospital and fails elsewhere. It had learned the machine, not the disease. Leakage is why surprisingly good results deserve suspicion before celebration.
Step 5 of 14Practice · Work it out
A team has 50,000 labeled customer reviews and keeps 20% aside as a test set. How many reviews are left for training (and validation)?
Step 6 of 14Chart
A common way to split labeled data
The model learns from the training slice, you tune settings on the validation slice, and you touch the test slice only once, at the end.
| Item | Share of the data |
|---|---|
| Training | 70% |
| Validation | 15% |
| Test | 15% |
Step 7 of 14Note
Step 8 of 14Learn
Three ways machines learn
Machine learning comes in three main flavors, depending on what kind of feedback the system gets.
Supervised learning uses labeled examples: each input comes with the right answer. It's the most common type in business. It solves two kinds of problems:
- Classification: predicting a category. Spam or not spam? Which of 10 digits is this handwriting? Will this customer cancel?
- Regression: predicting a number. What will this house sell for? How many units will we sell next week?
Unsupervised learning uses data with no labels and looks for structure on its own. A retailer might feed in customer purchase histories and let an algorithm group similar shoppers into clusters, discovering segments like "weekend bulk buyers" that nobody defined in advance. Unsupervised methods also spot anomalies, such as an unusual network traffic pattern that might be an attack.
Reinforcement learning involves an agent that takes actions in an environment and receives rewards or penalties. Through trial and error, it learns a strategy that maximizes total reward. It's how AI systems learned to play Go and video games at superhuman levels, and it's used in robotics and to fine-tune chatbots based on human ratings.
A useful shortcut: supervised learning learns from a teacher with an answer key; unsupervised learning explores without one; reinforcement learning learns from consequences, like training a dog with treats.
Large language models mix these ideas. Their main training is often called self-supervised: the labels come from the data itself, because the "answer" for each position in a text is simply the next word.
Step 9 of 14Practice · Sort into groups
Classify each task by the type of machine learning it most likely uses.
Tap an item, then tap its group (or drag it there).
Step 10 of 14Note
Step 11 of 14Practice · Fill in the blanks
Fill in the blanks
Predicting a category, such as spam or not spam, is called . Predicting a number, such as a sale price, is called .
Step 12 of 14Practice · Diagram
Three ways machines learn
A model groups thousands of support tickets into themes, with no categories given in advance. Which branch is that?
Tap the shape that answers the question, then press Check.
- Machine learning
- Supervised
Learns from examples that come with the right answer.
- Classification
Predicts a category: spam or not, which digit.
- Regression
Predicts a number: a price, a temperature.
- Unsupervised
Finds structure in data without labels.
- Clustering
Groups similar items, such as customer segments.
- Reinforcement
Learns by trial and error from rewards.
- Games, robot control
Step 13 of 14Practice · Choose one
A model scores 99% accuracy on its training data but only 61% on the test set. What is the most likely explanation?
Step 14 of 14Practice · True or false
In supervised learning, the label of an example should be included as one of its input features.
Lesson complete!