Understanding Data: Datasets, Features & Labels in Machine Learning
Data is the fuel of AI — and it all comes down to datasets, features, and labels. This beginner's guide explains how machine learning "sees" a problem, with a clear example table and Python you can run.
Every machine learning model has one thing in common: it learns from data. And almost all of that data boils down to three simple ideas — datasets, features, and labels. Get these, and suddenly every ML tutorial starts to make sense.
Once this clicked for me — that features are the questions and the label is the answer — the whole field stopped feeling mysterious. Let me make it click for you too.
This is Lesson 7 of the GyaanPost Learn AI roadmap. New to the series? Start with Lesson 1: What is Artificial Intelligence?
Why data is everything in AI
There's a famous saying in machine learning: "garbage in, garbage out." A model is only as good as the data it learns from. Great data with a simple model usually beats bad data with a fancy one. That's why understanding data comes first.
What is a dataset?
A dataset is just a table of information — like a spreadsheet. It has:
- Rows — each row is one example (also called a sample or record). One house, one email, one customer.
- Columns — each column is one piece of information about that example.
Here's a tiny dataset for predicting house prices:
| Size (sq ft) | Bedrooms | Location score | Price ($) ← label |
|---|---|---|---|
| 1000 | 2 | 7 | 200,000 |
| 1500 | 3 | 8 | 300,000 |
| 1200 | 2 | 6 | 240,000 |
Keep this table in mind — we'll use it to explain features and labels.
Features: the inputs (the "questions")
Features are the input columns — the information the model uses to make a prediction. In our table, the features are Size, Bedrooms, and Location score.
Think of features as the clues. To guess a house's price, you'd look at how big it is, how many bedrooms it has, and where it's located. Those clues are your features.
Labels: the answer (the "output")
The label is what you're trying to predict — the correct answer. In our table, the label is Price.
During training, the model sees both the features and the labels, and learns the relationship between them. Later, given only new features (a new house), it predicts the label (its price).
The simplest way to remember it: features are the questions you ask; the label is the answer you want.
Numerical vs categorical features
Features come in two main flavors:
- Numerical — numbers you can measure (size, age, price, temperature).
- Categorical — categories or labels (color, city, "yes/no", product type).
This matters because models handle them differently — categorical features often need to be converted into numbers first (something you'll learn when you start building).
Labeled vs unlabeled data
- Labeled data — every example includes the answer (like our price table). Used for supervised learning.
- Unlabeled data — examples with features but no answers. Used for unsupervised learning, where the model finds patterns on its own.
Which type you have decides which kind of machine learning you can do — the exact topic of the next lesson.
Training data vs test data
You don't give the model all your data. You split it:
- Training data — what the model learns from (usually ~80%).
- Test data — held back to check how well it does on examples it hasn't seen (~20%).
This is how you avoid fooling yourself: a model that memorized the training data but fails on new data isn't actually useful.
See it in Python (Pandas)
In practice, you load a dataset and separate features from the label like this:
import pandas as pd
data = pd.read_csv("houses.csv") # load the dataset
# Features = the input columns
X = data[["size", "bedrooms", "location_score"]]
# Label = the answer we want to predict
y = data["price"]
By convention, features are called X and the label is called y. You'll see this everywhere in machine learning.
Common mistakes
- Leaking the label into the features. Never include a column that secretly reveals the answer.
- Testing on training data. Always keep a separate test set — otherwise your results lie.
- Ignoring bad data. Missing values and outliers hurt models; clean first.
Key takeaways
- A dataset is a table: rows are examples, columns are information.
- Features are the input columns (the clues); the label is the answer you predict.
- Remember it as: features = questions, label = answer (X and y in code).
- Features are numerical or categorical; data is labeled or unlabeled.
- Split data into training and test sets so your results are honest.
👉 Next lesson: What is Machine Learning? Supervised, Unsupervised & Reinforcement Learning →
📬 Want each new AI lesson in your inbox? Subscribe to the GyaanPost newsletter and follow the roadmap from beginner to advanced.
Frequently Asked Questions
What are features and labels in machine learning?
Features are the input columns a model uses to make a prediction, like the clues in a problem. The label is the answer you want the model to predict. For example, to predict house price, size and bedrooms are features and price is the label.
What is a dataset in machine learning?
A dataset is a table of information, like a spreadsheet. Each row is one example or sample, such as a single house or customer, and each column holds a piece of information about that example.
What is the difference between labeled and unlabeled data?
Labeled data includes the correct answer for each example and is used for supervised learning. Unlabeled data has features but no answers and is used for unsupervised learning, where the model finds patterns on its own.
Why do we split data into training and test sets?
The training set is what the model learns from, usually about 80 percent of the data. The test set is held back to check how the model performs on examples it has not seen. This prevents you from being fooled by a model that only memorized the training data.
What is the difference between numerical and categorical features?
Numerical features are measurable numbers like size, age, or price. Categorical features are categories like color, city, or yes/no. Categorical features usually need to be converted into numbers before a model can use them.