4 Regression

Learn what regression predicts, how common regression models work, and how to interpret predictions and their limitations.

What predicts

is a supervised learning task: a model learns patterns from examples with known targets, then uses those patterns to predict targets for new examples. The is numerical and can vary across a range of values, unlike a classification prediction, which is a category.

A dataset contains examples described by and paired with a numerical . For instance, a home’s floor area and number of bedrooms can be , while its sale price is the . Other example targets include tomorrow’s temperature and the time needed to complete a delivery.

Baseline and linear models

A predicts the average in the training data for every example. It is a simple reference point; a more useful model should generally do better on data it has not seen.

predicts a as a weighted sum of . A simplified rent model is:

rent^=700+18(area in m2).\widehat{\text{rent}} = 700 + 18(\text{area in m}^2).

In this example, the model predicts a base rent of 700700 currency units, plus 1818 currency units for each square meter. With multiple , the model adds a term for each feature. chooses coefficients to minimize the sum of squared differences between observed and predicted targets.

Regularization, trees, and ensembles

methods, including and , add penalties on size. These methods can help when there are many or when overlap in the information they provide. can also shrink some coefficients to zero.

repeatedly divides examples according to feature values, then predicts a value for each resulting group. It can represent nonlinear patterns, but an overly deep tree can fit training examples too closely.

includes random forests, which average predictions from many trees, and gradient-boosted trees, which build trees in sequence to improve predictions. These models can capture complex relationships, but they are often less straightforward to interpret than a small linear model.

Interpreting predictions and coefficients

A prediction, written y^\hat{y}, is the model’s estimated for an example. When the actual value yy is known, compare it with the prediction: the is y−y^y - \hat{y}. A positive means the model predicted too low; a negative means it predicted too high.

For a linear model, a describes how the prediction changes with a feature when the other are held fixed. In the rent example, the area of 1818 means the predicted rent increases by 1818 currency units for each additional square meter, according to this model. This describes the model’s pattern; it does not prove that increasing an area causes rent to rise by that amount. Coefficients depend on the data, the included , and their units.

Prediction limits and generalization

Predictions are estimates, not guarantees. They may be unreliable when an input differs greatly from the training examples, when important are missing, or when the data’s patterns change. In particular, a linear model’s prediction far outside the range of training data is an and may not be realistic.

Check predictions against their context, and use to assess how well a model generalizes. Interpret predictions in the ’s units, while keeping in mind that their reliability can be limited for examples unlike those used in training.