Making Predictions from Data

Use a regression line to predict values, work backwards to a target, and judge when a prediction can be trusted.

Intermediate25 minLesson

Definition

Once you have a regression line y^=mx+b\hat{y} = mx + b, you can use it to make predictions. The symbol y^\hat{y} (read "y-hat") is the predicted value: the value the line expects, not a measured one.
There are two kinds of questions:
  • **Predict yy from xx**: substitute the xx-value and calculate y^=mx+b\hat{y} = mx + b.
  • **Find xx for a target yy**: set mx+bmx + b equal to the target and solve: x=y−bmx = \frac{y - b}{m}.
Where the xx-value lies matters:
  • Interpolation: xx is inside the range of the data. The prediction is usually reasonable.
  • Extrapolation: xx is outside the range of the data. The pattern may not continue, so the prediction is risky.
How much you can trust a prediction depends on the strength of the correlation: when rr is close to 11 or −1-1, the points hug the line and predictions are reliable; when rr is close to 00, they are only rough guesses.

Try it now

A regression line is y^=4x+10\hat{y} = 4x + 10. What is the predicted value when x=5x = 5?

Worked Examples

A class recorded hours studied (xx, from 1 to 8 hours) and test scores (yy, out of 100). The regression line is y^=5x+52\hat{y} = 5x + 52. Predict the score of a student who studies 6.56.5 hours.
1

Check where the x-value lies

The data goes from 11 to 88 hours, and 1≤6.5≤81 \le 6.5 \le 8 → Inside the data: interpolation
2

Substitute x = 6.5 into the equation

y^=5(6.5)+52\hat{y} = 5(6.5) + 52 → y^=5×6.5+52\hat{y} = 5 \times 6.5 + 52
3

Multiply

5×6.5=32.55 \times 6.5 = 32.5
4

Add the intercept

32.5+52=84.532.5 + 52 = 84.5 → y^=84.5\hat{y} = 84.5

Common Mistakes

Putting the target y-value in place of x: for a target score of 8080, calculating 5(80)+52=4525(80) + 52 = 452

Why it's wrong: 8080 is a score, so it is a yy-value. Substituting it for xx answers a different question (the score after 80 hours of study).

Correct: Set the equation equal to the target and solve for xx: 80=5x+5280 = 5x + 52, so x=5.6x = 5.6.

Trusting extrapolation: predicting 112112 points for 1212 hours of study

Why it's wrong: The pattern was only observed from 1 to 8 hours. Outside that range it can change, and here the score cannot even go above 100.

Correct: Always check the data range first. Mark predictions outside it as extrapolation and treat them with caution.

Rounding without thinking about the situation: reporting 84.584.5 points as exact, or rounding 5.65.6 hours down to 55

Why it's wrong: A prediction is an estimate, so extra decimals suggest more precision than it has. Rounding down a target can leave you short (5 hours predicts only 77 points).

Correct: Round to the precision of the data, and round up when you have to reach a goal or cover everyone (time, chairs, buses).

Treating every prediction as equally reliable

Why it's wrong: A line can always be calculated, even for scattered data. With r≈0.21r \approx 0.21 the actual values can be far from y^\hat{y}.

Correct: Look at the scatter plot or rr first: ∣r∣|r| close to 1 means a reliable prediction, ∣r∣|r| close to 0 means only a rough guess.

Interactive Visual

Function graph

05101520050100150Hours studiedTest scoreŷ(6.5, 84.5)

Tap or hover over the graph to read off values.

  • Predicted score ŷ = 5x + 52 = 84.5
  • Hours outside the data range (0 = interpolation) = 0 h
ŷ = 5x + 52Maximum score 100Data starts (1 h)Data ends (8 h)

Scatter Plot

Strong correlation: hours studied and test score

024685060708090100Hours studiedTest score

ŷ = 5x + 52

r = 0.992 · strong positive correlation

Tap a point to see its coordinates.

Scatter Plot

Weak correlation: hours of sleep and test score

5678960708090Hours of sleepTest score

ŷ = 2x + 59

r = 0.209 · weak positive correlation

Tap a point to see its coordinates.

Interactive Sandbox

Expression Calculator

Try these:

History

No calculations yet

Practice Problems

18 problems
Problem 1 of 18
Easy
A regression line is y^=4x+10\hat{y} = 4x + 10. What is the predicted value when x=5x = 5?

Why It Matters

Predictions are the main reason people fit a line to data in the first place:
  • Planning: A school fair predicts how many visitors to expect, so it knows how many chairs to set out.
  • Health: Doctors compare a child's height with growth models to see whether growth is on track.
  • Delivery apps: Apps estimate how long your order will take from the distance to the restaurant.
  • Batteries: Phones estimate how many hours of battery are left from how fast it is draining.
A prediction is only useful if you also know how far to trust it. Knowing the difference between interpolation and extrapolation, rounding sensibly and checking the correlation stops you from believing numbers like a test score of 112 out of 100.

Real World Applications

Child Growth Charts

Doctors compare a child's height with growth models. A simple model for ages 2 to 10 is $\hat{y} = 6x + 77$, where $x$ is age in years and $\hat{y}$ is height in cm. The model only works for those ages: for an adult of 40 it would predict $317$ cm.

Example:

At age 5 the model predicts 6(5)+77=1076(5) + 77 = 107 cm.

1Try It Yourself

A growth model for ages 2 to 10 is y^=6x+77\hat{y} = 6x + 77 (height in cm, age xx in years).

What height does the model predict for an 8-year-old?

Step 1: Write the mathematical expression

Substitute x=8x = 8:

Delivery Time Estimates

Food delivery apps fit lines to past orders to estimate delivery times. One app found $\hat{y} = 3x + 8$, where $x$ is the distance in km (orders from 1 to 12 km) and $\hat{y}$ is the time in minutes.

Example:

For a restaurant 5 km away the app predicts 3(5)+8=233(5) + 8 = 23 minutes.

2Try It Yourself

The delivery model is y^=3x+8\hat{y} = 3x + 8 (minutes, distance xx in km, data from 1 to 12 km). The app wants to promise delivery in 35 minutes.

Up to what distance in km can the app make that promise?

Step 1: Write the mathematical expression

Solve 35=3x+835 = 3x + 8 for xx:

Phone Battery Forecasts

Phones estimate the remaining battery from how fast it is draining. Measurements while streaming video gave $\hat{y} = 100 - 8x$, where $x$ is hours of video (data from 0 to 10 hours) and $\hat{y}$ is the battery level in percent.

Example:

After 6 hours of video the model predicts 100−8(6)=52%100 - 8(6) = 52\%.

3Try It Yourself

The battery model is y^=100−8x\hat{y} = 100 - 8x (percent, xx in hours, data from 0 to 10 hours). Someone asks what the battery will show after 15 hours of video.

What value does the model predict for 15 hours?

Step 1: Write the mathematical expression

Substitute x=15x = 15:

Key Takeaways

  • 1To predict yy, substitute xx into y^=mx+b\hat{y} = mx + b; y^\hat{y} is a predicted value, not a measured one
  • 2To find the xx for a target yy, set mx+bmx + b equal to the target and solve: x=y−bmx = \frac{y - b}{m}
  • 3Interpolation predicts inside the data range and is usually reasonable
  • 4Extrapolation predicts outside the data range and is risky: it can even give impossible values
  • 5Round predictions to a sensible precision, and round up when you must reach a goal or cover everyone
  • 6Predictions are reliable when ∣r∣|r| is close to 1 and only rough guesses when rr is close to 0

Frequently Asked Questions

The hat shows that the value comes from the line and is a prediction. The real, measured value is yy. Keeping them apart reminds you that a real result can be above or below the prediction.
The hat shows that the value comes from the line and is a prediction. The real, measured value is yy. Keeping them apart reminds you that a real result can be above or below the prediction.
Not always. A little outside the data (for example x=0x = 0 or x=9x = 9 when the data goes from 1 to 8) can still be a fair estimate. The further you go, the more likely the pattern changes, so say clearly that you are extrapolating.
A common rule of thumb: ∣r∣≥0.7|r| \ge 0.7 is strong, 0.40.4 to 0.70.7 is moderate and below 0.40.4 is weak. Even with a strong correlation, a single prediction can be a few points off.
Solving y=mx+by = mx + b for xx gives a good estimate for planning, as in the study-hours example. Statisticians fitting a model only to predict xx would calculate a separate line with xx as the response variable, so treat the answer as an estimate.

Glossary

Predicted value y^\hat{y}
The value of yy that the regression line gives for a chosen xx
Data range
The interval from the smallest to the largest xx-value in the data
Interpolation
Predicting for an xx-value inside the data range
Extrapolation
Predicting for an xx-value outside the data range; risky because the pattern may change
Explanatory variable
The variable xx used to make the prediction (for example hours studied)
Response variable
The variable yy being predicted (for example the test score)

Formula Card

Predict y from x

y^=mx+b\hat{y} = mx + b

Substitute the x-value and calculate

Find x for a target y

x=y−bmx = \frac{y - b}{m}

Subtract the intercept, then divide by the slope

Interpolation check

xmin⁡≤x≤xmax⁡x_{\min} \le x \le x_{\max}

If x is inside the data range, the prediction is interpolation; otherwise it is extrapolation

Today's challengeOne problem, three tries

More in This Topic