Datasets, Labels and Features

Updated · 6 min read
easyPython 3.13aidatadatasetsfeatureslabelsbeginnersinterview

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.

A dataset: examples, features, labels and the three-way split

Examples, Features and Labels

TermMeaningIn the house tableIn the cat and dog photos
ExampleOne item in the datasetOne house (one row)One photo
FeatureA piece of input the model looks atArea, bedrooms, age, locationThe pixels of the photo
LabelThe correct answer the model learns to predictThe 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:

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)
Output
Features: {'area': 1100, 'bedrooms': 3, 'age': 12}
Label: 260000
Train: 7000 Validation: 1500 Test: 1500

Training, 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.

PartTypical shareWhat it is for
Training setAbout 70%The examples the model learns from
Validation setAbout 15%Checking progress, tuning settings and comparing models
Test setAbout 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:

  1. In a spam filter dataset, what is one example, and what is its label?
  2. What is the difference between a feature and a label?
  3. Why must the test set stay unseen?

Quick check: datasets

4 questions
1In a dataset of house sales used to predict prices, what is the label?
2What is a feature?
3Which part of a dataset gives the final, honest score?
4A model scores 99% on its training data but 60% on new data. What most likely happened?

Key Takeaways

Quick reference

TermMeaning
DatasetA collection of examples for training or testing
ExampleOne item in a dataset, such as one house or one photo
FeatureAn input the model looks at
LabelThe correct answer the model learns
Training setThe examples the model learns from
Validation setExamples for tuning and comparing models
Test setUnseen examples for the final check

Was this tutorial helpful?

Lesson 10 of 186