Skip to content

Learning from dataLesson 1 of 6

Dots with a hidden rule

Regression functions and noise

Suppose you know how much a campaign spent on advertising. You want to predict its sales. Before choosing a model, we need to say what a prediction is trying to estimate.

Here are some rows from a dataset of 200 campaigns. Advertising spends are in thousands of dollars; sales are in thousands of units.

campaignTVradionewspapersales
1230.137.869.222.1
244.539.345.110.4
317.245.969.39.3

The three spends are the inputs, also called features or predictors. Sales are the output, also called the response or target.

notationwhat it refers to here
X=(X1,,Xp)X=(X_1,\ldots,X_p)the input for a randomly selected campaign
x=(230.1,37.8,69.2)x=(230.1,37.8,69.2)one particular input
YY; y=22.1y=22.1the random output; one observed output
p=3p=3number of features in each row
N=200N=200number of rows

A subscript can identify a feature or a row. Here xjx_j means feature jj of one input; later (xi,yi)(x_i,y_i) will mean training example ii. Check what the author is indexing before doing any arithmetic.

Identical advertising spends can produce different sales. The inputs leave out weather, competitors, and other influences. Imagine repeating a campaign with the same input xx: the possible sales form a conditional distribution, YX=xY\mid X=x.

Define f(x)f(x) as that distribution’s mean:

f(x)=E[YX=x].f(x)=\mathbb E[Y\mid X=x].

Read from the inside out: fix the input at xx, consider the possible outputs YY, and average them. The answer is one number for this input. Repeating the calculation at different inputs defines a function.

This is the regression function. It describes average sales associated with the input. It does not, by itself, prove what would happen if you intervened and changed the advertising budget.

Define the leftover; then state the assumptions

Section titled “Define the leftover; then state the assumptions”

For each outcome, subtract its conditional mean. Call the leftover ε\varepsilon (epsilon):

ε=Yf(X),Y=f(X)+ε.\varepsilon=Y-f(X),\qquad Y=f(X)+\varepsilon.

For example, at an input whose mean sales are 13, outputs 12.6, 13.9, and 12.5 have leftovers −0.4, +0.9, and −0.5. These three happen to average to zero. A small random sample need not do so exactly; the population of possible leftovers averages to zero at every input, by the definition of ff:

E[εX=x]=0.\mathbb E[\varepsilon\mid X=x]=0.

That conditional statement is stronger than merely saying the leftovers average to zero when all inputs are mixed together.

For the examples in this module, we additionally assume

Var(εX=x)=σ2.\operatorname{Var}(\varepsilon\mid X=x)=\sigma^2.

In words: the noise has the same variance at every input. This is constant noise variance, or homoscedasticity. It is a simplifying assumption, not part of the definition of regression. Real data can have more scatter at some inputs than others; then write σ2(x)\sigma^2(x) instead.

Our simulations generate noise independently of XX. Independence fixes the whole noise distribution across inputs; constant variance fixes only its spread. Neither independence nor constant variance is needed to define the conditional mean.

Compare the average of observed outputs with their population mean. More observations improve the estimate of the mean; individual outputs keep varying.

The function you know and the function you estimate

Section titled “The function you know and the function you estimate”

In real data you see the rows, not ff. A model fitted from them is written f^\hat f—“f hat.” The hat tells you this is an estimate.

Numerical outputs lead to regression. Categorical outputs lead to classification. Without an output column, grouping similar inputs is one possible unsupervised task, called clustering. This module focuses on regression scored by squared error.

Prediction asks whether f^\hat f makes useful guesses. Statistical inference asks what the data support about relationships and parameters. Causal conclusions need additional assumptions or experimental design.

We defined ff using a mean. Why should the mean be the prediction you want?

Definition

Read the full glossary entry →