Rows, features, and targets.
Learn what one example is, how a table represents it, and what the model is allowed to see.
Start with the meaning.
A dataset is an organised collection of examples. In a table, one row usually represents one example: one house, one message, one patient visit, or one transaction. Columns describe properties of that example. A feature is an input property available at prediction time. A target is the answer the model is meant to learn to predict. For house prices, floor area might be a feature and sale price the target. The model must not be given the sale price as an input when asked to predict it.
The letters X and y are conventional shorthand. X is often a two-dimensional table: rows are examples and columns are features. y is often a one-dimensional sequence with one answer per row. If X has 100 rows, y should have 100 corresponding answers in the same order. This alignment is a contract, not merely a formatting preference. A shifted target column can produce code that executes normally while learning nonsense.
How the idea works.
Data has types as well as shapes. A measured area is numeric, a neighborhood name is categorical, and a review is text. A missing value means a measurement was not supplied or could not be found. The number 0 may be a valid measurement, so it must not automatically be treated as missing. The category “unknown” is also different from a category that happens to have zero examples. Later preprocessing chapters explain how to represent these cases for particular algorithms.
The most important feature question is temporal: would this value exist when the model makes its prediction? A delivery-time model may know the route and departure time but not the eventual arrival scan. An apparent feature created after the outcome is a leak of the answer. The model may look brilliant in a stored table and fail in use because the leaked column is unavailable. Write down the prediction moment before choosing features.
Rows may not be independent. Several visits from one person, repeated measurements from one machine, or photos of the same object can share information. If near-duplicates appear in both training and evaluation data, the score may be too optimistic. The identity of an example and the way examples relate to one another influence how the data should later be divided.
Follow the code.
rows = [
{"area": 55, "rooms": 2, "price": 180},
{"area": 80, "rooms": 3, "price": 260},
{"area": 95, "rooms": 3, "price": 310},
]
X = [[row["area"], row["rooms"]] for row in rows]
y = [row["price"] for row in rows]
print(X)
print(y)Each dictionary is one house. The keys area, rooms, and price name its fields. The first list comprehension builds X by taking area and rooms from each row; it produces [[55, 2], [80, 3], [95, 3]]. The second builds y from the prices and produces [180, 260, 310]. The nested brackets in X matter: each inner list is one example with two feature values. The price unit has not been specified here, so a real dataset would need to document it.
This code only shapes data; it has not trained anything. The model would later receive X and y during fitting. For a new house, it would receive only an input row such as [70, 2]. If price accidentally joined that input row, the model could learn to copy the answer. Keeping features and target separate in code mirrors the real-world separation between information known now and an outcome known later.
What the result does not say.
A dataset needs a data dictionary: column name, meaning, unit, allowed values, and collection time. “Age” could mean years, months, or age at a different event. “Income” could be monthly or annual. Without these definitions, a correct algorithm can still answer the wrong question. Data preparation begins by understanding what the columns claim to mean.
Data quantity alone is not enough. Ten thousand nearly identical rows may teach less than a smaller collection that covers the range of situations the model will encounter. Representative data and trustworthy labels are the foundation of useful generalisation.
One clear idea.
A row is one case, X contains information available at prediction time, and y contains the answer to learn.
The ML cookbook
Complete, explained Python workflows sit alongside this reading course.