Datasets, Labels and Features
How many photos does it take to teach a computer the difference between cats and dogs? Navika's project team collects 10,000 photos, each tagged "cat" or "dog". That collection is a dataset. Before any learning starts, they have to decide what each photo means to the model, what answer it should learn, and which photos to keep aside for testing.
This lesson explains those words, example, feature and label, and why a dataset is split into three parts.
What a Dataset Is
A dataset is a collection of examples used to train or test an AI model. The 10,000 tagged photos are a dataset. So is a table of past house sales, a folder of customer reviews marked positive or negative, or a set of recorded sentences with their written text.
Examples, Features and Labels
| Term | Meaning | In the house table | In the cat and dog photos |
|---|---|---|---|
| Example | One item in the dataset | One house (one row) | One photo |
| Feature | A piece of input the model looks at | Area, bedrooms, age, location | The pixels of the photo |
| Label | The correct answer the model learns to predict | The price | "cat" or "dog" |
Features are the questions; the label is the answer. A model learns how the features relate to the label, then predicts the label for new examples that don't have one yet, such as the new house in the picture.
Here is one example split into its features and label in Python:
# A tiny dataset: each dictionary is one example (one house)
houses = [
{"area": 1100, "bedrooms": 3, "age": 12, "price_usd": 260_000},
{"area": 2000, "bedrooms": 4, "age": 5, "price_usd": 475_000},
{"area": 2400, "bedrooms": 4, "age": 2, "price_usd": 570_000},
]
first = houses[0]
features = {k: v for k, v in first.items() if k != "price_usd"}
print("Features:", features)
print("Label:", first["price_usd"])
# Splitting 10,000 photos into training, validation and test sets
total = 10_000
train, validation = int(total * 0.70), int(total * 0.15)
print("Train:", train, "Validation:", validation, "Test:", total - train - validation)Features: {'area': 1100, 'bedrooms': 3, 'age': 12}
Label: 260000
Train: 7000 Validation: 1500 Test: 1500Training, Validation and Test Sets
Here is an analogy. A teacher doesn't put the exact practice questions on the final exam, or the exam would only show who memorized answers. Datasets are split for the same reason.
| Part | Typical share | What it is for |
|---|---|---|
| Training set | About 70% | The examples the model learns from |
| Validation set | About 15% | Checking progress, tuning settings and comparing models |
| Test set | About 15% | A final check on examples the model has never seen |
The test set must stay unseen until the end. If the model sees test examples while learning, its score looks better than it really is. The shares vary; 80/10/10 and other splits are common too. Later chapters return to splitting and testing in detail.
Common Mistakes
Testing on the training data. A model can do well on examples it memorized and still fail on new ones.
Confusing features and labels. The label is what you want to predict; everything the model looks at to predict it is a feature.
Using a feature that won't exist at prediction time. For example, using "the day the house sold" to predict a price before the house is sold.
Interview Corner
What are features and labels?
Features are the inputs a model uses, such as a house's area, bedrooms and location. The label is the correct answer the model learns to predict, such as the price.
Why split data into training, validation and test sets?
The model learns from the training set, the validation set is used to tune and compare models, and the test set gives an honest final score on examples the model has never seen. Testing on training data hides whether the model really learned general patterns.
Practice
Exercise: build a small dataset. Create a table of 20 products with the columns name, price, category and rating (1 to 5). Then answer: if an AI system recommended products from it, which columns would be features, and what could be the label? Finally, decide which 14 rows you would train on, which 3 you would use for validation, and which 3 you would keep for the test.
Check your understanding:
- In a spam filter dataset, what is one example, and what is its label?
- What is the difference between a feature and a label?
- Why must the test set stay unseen?
Key Takeaways
Quick reference
| Term | Meaning |
|---|---|
| Dataset | A collection of examples for training or testing |
| Example | One item in a dataset, such as one house or one photo |
| Feature | An input the model looks at |
| Label | The correct answer the model learns |
| Training set | The examples the model learns from |
| Validation set | Examples for tuning and comparing models |
| Test set | Unseen examples for the final check |
Was this tutorial helpful?