Lesson 1 of 3
Features, targets and learning from examples
Define a prediction task, fit a small model and use it on a new input.
Go to the exercise ↓A labeled example pairs an input with an observed outcome
Supervised learning fits a prediction rule from labeled examples. Each example contains features, the information available when you make a prediction, and a target, the outcome you want to predict. A numerical target, such as a duration, defines a regression task. A category, such as spam or legitimate, defines a classification task.
The prediction time determines which columns are usable. To estimate a delivery duration when an order is placed, you can use the route distance known then. The actual arrival time becomes available after delivery. Including that arrival time as an input would give training information that a live prediction cannot use.
An example needs a clear unit as well as a label. One delivery can be one row. If a row combines several deliveries, its distance and duration must describe the same combined task. A precisely defined target makes incorrect labels and missing inputs easier to detect.
Training chooses parameters that reduce prediction error
A model is a family of rules with adjustable parameters. A straight-line model predicts duration = slope × distance + intercept. The slope describes how the prediction changes for one more kilometer; the intercept is its prediction at zero distance. Those parameters summarize the relationship represented by this model.
Training chooses parameter values using the labeled examples. For ordinary least squares, the objective is to minimize the sum of squared differences between predictions and observed targets. Squaring makes a large error contribute more than several small errors with the same total absolute size. The lab computes the least-squares line directly; it does not run a remote AI service.
Our four synthetic training deliveries are (1 km, 12 min), (2 km, 14 min), (3 km, 16 min) and (4 km, 18 min). The fitted slope is 2 minutes per kilometer and the intercept is 10 minutes. The line matches these examples exactly because we constructed them that way. Real observations have noise and omitted causes.
Inference applies the fitted rule to a new input
After fitting, inference substitutes a new feature value into the model. At 3.5 kilometers, the fitted line predicts 17 minutes. This calculation uses the distance and the fitted parameters; it does not require the new delivery’s actual duration. That duration is collected later to measure error.
A prediction for 6 kilometers is an extrapolation because the training distances stop at 4 kilometers. The formula still produces a number, but these four examples provide no measurement of error at that distance. A real evaluation needs held-out examples from the distances and conditions where you plan to use the model.
A fitted association also does not establish a cause. Longer routes may coincide with different traffic or restaurant preparation times. Changing one input in a model is a calculation; changing that condition in the world may produce a different outcome.
Fit a line and make a prediction
Loading your exercise…