Fit a Line by Minimizing Error
The dispatcher needs a numeric estimate of minutes late.
Read the full lesson and open its transcript below. A narrated video will be added after production.
What you will learn
The dispatcher needs a numeric estimate of minutes late.
A practical question
A dispatcher wants more than a warning that a delivery will be late. She wants an estimate of how many minutes it may arrive after the scheduled time. That changes our learning task: the output is a number. A simple starting point is linear regression. Before fitting anything, write down which facts are actually known when the trip is planned, such as distance, route type, and scheduled departure time. Actual arrival time is the answer we want to predict, so it cannot be an input for a future trip.
The useful idea
A linear model adds contributions from its inputs to make a prediction. During training, it adjusts their coefficients to reduce a chosen error. A common choice squares each prediction error before averaging, which makes a very large miss count more strongly than several small ones. That can be useful when severe lateness matters, but it also makes unusual records influential. The fitted line is a description learned from examples, not a rule that every road and every traffic condition must obey.
Work through the example
Suppose the first model uses trip distance and a route indicator. Fit it on earlier trips, then plot predicted minutes against actual minutes on a later group that was held out from fitting. Look separately at short city trips and long highway trips. If the model consistently underestimates one group, an overall average error hides a useful warning. Ask whether a missing factor, such as departure time, was available before the trip and could be evaluated fairly. Do not add a field merely because it improves the score after the delivery happened.
Limits and next step
A strong baseline is valuable even when it is imperfect: it tells us what more complex models must improve upon. Record the target units, the features, the training period, and the held-out period so another person can reproduce the comparison. If a few extreme trips dominate the squared error, show their individual cases beside the summary number. In the next lesson, we will read a fitted coefficient carefully and avoid turning an association inside the model into a claim about cause.
Worked example
Fit a distance-and-route linear baseline on earlier deliveries. Compare predicted and actual minutes on later trips, then inspect errors separately for short city routes and long highway routes.
Quick check: test your understanding
Try it yourself: A model has a low average error but repeatedly underestimates long highway routes. Why is the average not enough, and what should the dispatcher inspect before adding another input?
Check the reasoning
The average hides a systematic error for one group. Inspect held-out residuals and candidate inputs, and confirm that each new input would have been known before departure.
What is the main idea behind fit a line by minimizing error?
Linear regression chooses coefficients to minimize a defined error, often squared residuals.
How is it used in the example?
Fit a distance-and-route baseline and compare predicted versus actual minutes on held-out trips.
What limitation should be checked?
A straight-line approximation can miss nonlinear route effects.
Further reading
Machine Learning — Tom M. Mitchell.
Original ToolsInVision teaching examples. Editorial approach · Suggest a correction
Accessible referenceLesson 37 transcript343 words · Narration ready for the upcoming videoOpen transcript
A dispatcher wants more than a warning that a delivery will be late. She wants an estimate of how many minutes it may arrive after the scheduled time. That changes our learning task: the output is a number. A simple starting point is linear regression. Before fitting anything, write down which facts are actually known when the trip is planned, such as distance, route type, and scheduled departure time. Actual arrival time is the answer we want to predict, so it cannot be an input for a future trip.
A linear model adds contributions from its inputs to make a prediction. During training, it adjusts their coefficients to reduce a chosen error. A common choice squares each prediction error before averaging, which makes a very large miss count more strongly than several small ones. That can be useful when severe lateness matters, but it also makes unusual records influential. The fitted line is a description learned from examples, not a rule that every road and every traffic condition must obey.
Suppose the first model uses trip distance and a route indicator. Fit it on earlier trips, then plot predicted minutes against actual minutes on a later group that was held out from fitting. Look separately at short city trips and long highway trips. If the model consistently underestimates one group, an overall average error hides a useful warning. Ask whether a missing factor, such as departure time, was available before the trip and could be evaluated fairly. Do not add a field merely because it improves the score after the delivery happened.
A strong baseline is valuable even when it is imperfect: it tells us what more complex models must improve upon. Record the target units, the features, the training period, and the held-out period so another person can reproduce the comparison. If a few extreme trips dominate the squared error, show their individual cases beside the summary number. In the next lesson, we will read a fitted coefficient carefully and avoid turning an association inside the model into a claim about cause.