Features targets and samples
Quick answer
A sample is one observation used by a learning system. A feature is an input value used to make a prediction. A target (or label in supervised learning) is the outcome the model is trained to predict. The same dataset can support different tasks, so these roles depend on the question.
Read a parcel dataset
Consider three synthetic parcels. Each row represents one dispatched parcel. Weight is in kilograms, distance in kilometers, and late is 1 when the parcel arrives after its promised time and 0 otherwise. The weight and distance are known at dispatch; late is recorded after arrival. A Python list of dictionaries stores these rows; a dictionary associates names with values.
parcels = [ {"weight_kg": 2, "distance_km": 10, "late": 0}, {"weight_kg": 4, "distance_km": 80, "late": 1}, {"weight_kg": 1, "distance_km": 25, "late": 0},]row = parcels[1]print([row["weight_kg"], row["distance_km"]])print(row["late"])Expected output:
[4, 80]1Index 1 selects the second sample because Python starts counting at zero. The feature values are 4 and 80; the target value is 1.
Prepare inputs separately from outcomes
A model expects a consistent feature order. Build a feature list for each sample and a separate list of labels. The feature list and target list must use the same row order.
parcels = [(2, 10, 0), (4, 80, 1), (1, 25, 0)]features = []labels = []for weight, distance, late in parcels: features.append([weight, distance]) labels.append(late)print(features)print(labels)Expected output:
[[2, 10], [4, 80], [1, 25]][0, 1, 0]Each feature row has two inputs. There are three target values, one for each sample.
Availability matters
At dispatch, promised delivery time may be available, but actual arrival time and late status are not. An identifier can be useful for joining records, yet may not be a meaningful model input. Document units, missing values and when each value becomes known.
Using an outcome or a future-derived input to predict that same outcome is a form of leakage: information is available during development that will not be available when the prediction is made.
Common mistake
Do not include late among features merely because it exists in historical rows. Doing so gives the model the answer instead of teaching a usable relationship.
Practice and next steps
A parcel row contains weight, distance, actual arrival time and late status. Choose two valid dispatch-time features and one target. Next, learn what happens to those examples during training.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Features targets and samples — knowledge check
Apply the concepts from this lesson to small fictional scenarios.
In a dispatch-time delay dataset, which value is the target?
What is one sample in the example?
Which field must be excluded from dispatch-time inputs?
For row (3, 40, 1) ordered as weight, distance, late, what is the feature vector?
Why must feature and label arrays preserve the same row order?