Data, features and labels
Every supervised problem is a table: rows are examples, feature columns are what you know, and the label column is what you want to predict.
In 60 seconds
Data, features and labels
Every supervised problem is a table: rows are examples, feature columns are what you know, and the label column is what you want to predict.
- Row (example, sample): one thing we know about, such as one flower, one loan application or one field.
- Feature: a column the model is allowed to use as input, such as petal length or rainfall.
- Label (target): the column we want to predict, such as the flower's species or the crop yield.
X (a table, capital letter) and the labels y (one column, small letter).A real toy dataset: iris flowers
from sklearn.datasets import load_iris
iris = load_iris(as_frame=True)
X = iris.data # features: a pandas DataFrame
y = iris.target # labels: 0, 1 or 2
print("Rows and feature columns:", X.shape)
print("Feature names:", list(X.columns))
print("Species names:", iris.target_names.tolist())
print()
print(X.head())
print()
print("How many of each label:")
print(y.value_counts().sort_index())Two kinds of label, two kinds of problem
| Label looks like | Problem type | Examples |
|---|---|---|
| A number on a scale | Regression | Crop yield, house rent, travel time |
| One of a few groups | Classification | Spam or not, species, loan approve or reject |
Good features and bad features
- Row numbers or ids, which only carry order, not meaning
- Anything you only learn after the answer is known
- A copy of the label under a different name
- Information that is personal and not needed
- Measurements known at prediction time
- Things that plausibly affect the label
- Recorded the same way for every row
- Collected with consent and a clear purpose
Numbers only, please
X.describe(). Which feature has the biggest spread of values?Watch and read more
Lab
The wine dataset split cleanly into a feature table X and a label column y, with no leakage.
The problem
The wine dataset has 178 wines, 13 chemical measurements each, and a label for which of three growers made it.
- Run the starter. It prints the full table, which includes a
targetcolumn: the label. - The starter sets
X = df. That leaks the label into the features. Fix it soXhas only the 13 feature columns. - Set
yto the label column. - Set
n_classesto the number of different labels, computed fromy(do not type the number by hand). - Print which feature has the largest average value.
Practice lab
Edit the code and run it. Python runs in your browser — nothing is sent to our server.
No output. Add print(...) to see values.
You are done when
Hard questions
Try to answer before you reveal. If you can answer these, you understood the lesson.
Q1The largest-average feature is not necessarily the most useful for prediction. Why?Reveal
The average depends on the unit. A column measured in large units has a big average, but that says nothing about whether it separates the three growers. Usefulness depends on how differently the feature behaves across the labels, which later lessons measure with models.
Q2Suppose the wine table also had a column "grower_name" in text. What would happen if you kept it in X?Reveal
It is the label written in words, so it is leakage: a model would learn to read the name and look perfect. In real use you would not have the grower's name, since that is exactly what you want to predict. Remove any column that is the answer in disguise.
Questions people ask
Is the label always one column?
In this track, yes. Some problems predict several things at once, but the ideas are the same.
What if a feature is text, like a comment?
Text must be turned into numbers. Simple ways count words; modern ways use embeddings. For this track we stick to tables of numbers.
Should I use every column I have?
No. Remove ids, leaked columns and personal data you do not need. More columns can also make overfitting easier. Start with features that make sense and add more if testing shows they help.
What does as_frame=True do?
It returns the data as a pandas DataFrame with column names, instead of a bare numpy array. That makes it easier to read and check.
Lesson test
5 questions. Get 3 right (60%) to pass and complete this lesson.