A homeowner asks, “How much might my house sell for?” The answer needs an amount of money. Predicting that amount is a regression task.
In chapter 1, training used examples with known answers. Prediction used the trained model for a new input. Here, we give that kind of amount-predicting task its name: regression.
Why do we need regression?
Often, we have to make a decision before we know the actual amount. A seller needs an asking price before a home sells. Regression can use past examples to estimate that unknown amount.
Here are three practical uses. The example predictions are made up.
- Home pricing. Use a home’s size, location, and condition to estimate a sale price, such as $330,000. This can help a seller choose an initial asking price.
- Delivery planning. Use the route, distance, and traffic to estimate a trip time, such as 24 minutes. This helps give the customer an arrival window.
- Rainfall planning. Use weather measurements to estimate how much rain will fall, such as 8 mm over the next six hours. This can help a farmer plan watering.
The useful part is the estimated amount: it gives us something to plan with while the actual answer is unknown.
Learn from homes that already sold
Training examples pair information about a home, such as its size and location, with its known sale price. The sale price is the answer we want the model to learn to predict, also called the target or label.
For a new home, we provide its information without its future sale price. The trained model gives an estimate. Our illustrative example is $330,000. All prices in this chapter are made up.
The answer measures an amount
$330,000 and $330,500 are both possible estimates. The difference between them, $500, has a meaning: it is an amount of money.
Other regression tasks can estimate a travel time, a temperature, or a weight. Always keep the unit with the answer: dollars, minutes, degrees, or grams.
An estimate can be wrong
Suppose the home actually sells for $340,000. Our $330,000 estimate was $10,000 too low. A regression model predicts an amount; it does not guarantee the actual outcome.
How far off was the estimate?
Our illustrative estimate is $330,000. Change the actual sale price and check the gap. This calculator measures the miss; it does not train a price model.
The estimate missed by .
Count the distance between the two prices. An estimate below the sale price can miss, and an estimate above it can miss too.
One quick check
A model estimates $330,000. Could the home actually sell for $335,000?
Choose one answer.
Regression in one infographic
Known prices, a new home, an estimated amount, and the actual outcome.
Code and sources
Run the price-gap example
Optional: Node.js 20 or newer, no extra packages. Copy the full source into regression-example.mjs. It checks an illustrative estimate against an actual price; it does not train a price predictor.
node regression-example.mjsEstimated price: $330,000
Actual sale price: $340,000
Gap: $10,000Change actualSalePrice to $320,000 or $330,000 and run again.
Full source
// Fictional home prices for an introductory regression lesson.
export const HOME_EXAMPLE = Object.freeze({ estimatedPrice: 330000, actualPrice: 340000 });
export const KNOWN_PRICES = Object.freeze(["$240,000", "$350,000", "$290,000"]);
export function formatPrice(value) {
return "$" + value.toLocaleString("en-US", { maximumFractionDigits: 0 });
}
export function priceGap(estimate, actual) {
if (![estimate, actual].every(value => Number.isFinite(value) && value >= 0)) {
throw new RangeError("Use nonnegative, finite prices.");
}
return Math.abs(actual - estimate);
}
// The estimate is illustrative, not the result of a trained price model here.
// Change the actual price to see how far the estimate missed.
const actualSalePrice = 340000;
console.log("Estimated price: " + formatPrice(HOME_EXAMPLE.estimatedPrice));
console.log("Actual sale price: " + formatPrice(actualSalePrice));
console.log("Gap: " + formatPrice(priceGap(HOME_EXAMPLE.estimatedPrice, actualSalePrice)));
Sources and teaching notes
The definition follows Google’s regression definition. Google’s supervised-learning introduction explains known labels, training, and prediction. The home drawings and prices are illustrative. A trained home-price model is not running on this page.
For a real travel-time application, see Google’s explanation of travel-time prediction. The practical examples above use made-up predictions.
← Chapter 1: Learning from examples
Chapter 3: Classification →


