On this concept: Formula

Not sure which lesson to do first? Find your level and get a plan →

Statistics · Grade 9-12

Line of Best Fit

The line of best fit (trend line) is the straight line that best represents the overall trend in a scatter plot by minimizing the sum of squared vertical distances between the line and all data points.

y^=mx+b

Quick Answer

The line of best fit (trend line) is the straight line that best represents the overall trend in a scatter plot by minimizing the sum of squared vertical distances between the line and all data points. Draw or compute it when a scatter plot shows a roughly straight trend and you want to summarize that trend or predict y for a new x. Its slope says how much y changes per unit of x, and its intercept is the predicted y when x=0. Its predictions are trustworthy only inside the range of the data, and only when the cloud really is straight.

Why This Matters

A trend line turns a cloud of points into a rule you can use: "each extra hour of study goes with about 5 more points", or "this taxi charges a $3 base plus $2 per kilometre". Without it, predictions are guesses read off scattered dots. Used carelessly, it misleads: forced through the origin, stretched far past the data, or laid over a curve.

Intuitive Explanation

Five students report hours studied and test score: (1, 62), (2, 68), (3, 71), (4, 77), (5, 82). The dots climb in a nearly straight band. Lay a ruler across them so that it runs through the middle of the cloud, with dots on both sides, passing the point of averages (3,72). That ruler edge is a line of best fit. Through (1,62) and (5,82) it rises 20 points over 4 hours, a slope of 5, so y^=5x+57.

"Best" has a precise meaning. For each dot, measure the vertical gap between the dot and the line, square it, and add up the squares. The least-squares line is the one that makes this total as small as possible. Squaring stops gaps above and below from cancelling and punishes big misses heavily, which is also why one far-off point can tilt the line noticeably. The hat on y^ marks a predicted value, not a score any student actually got.

A straight line is a model, and it can be the wrong one. Hot cocoa cools fast and then slowly: 90, 66, 50, 39, 32 and 27 °C at 5-minute steps. Software will still fit a line, y^≈81.2−2.45x, but the dots sit above it at both ends and below it in the middle, the mark of a curve. The same line predicts about −17 °C after 40 minutes, colder than the room. Before using a trend line, check that the cloud is straight and that you are predicting inside the data's range.

Think of it like this. A line of best fit is like a straight road built through a scattered village: it cannot pass every house, so it takes the route that stays as close as it can to all of them at once. If the village curves around a lake, no straight road serves it well, and you need a curved model instead.

Core idea. A single straight line through a roughly linear cloud summarizes the trend: its slope is the typical change in y per unit of x, and its equation gives predictions that are trustworthy only within the data's range and only if the cloud is straight.


When to Use

Use a line of best fit when a scatter plot of paired numerical data shows a roughly straight trend and the question asks you to predict, estimate, or describe a rate of change. Read the slope as change in y per unit of x and keep predictions inside the observed x-range. If the dots curve, a straight line is the wrong model; if you only need the strength of the link, use the correlation coefficient; for the exact least-squares equation and its errors, use linear regression.

Tip. Ask: Are you drawing or reading a straight trend line on a scatter plot to summarize the dots and estimate values?

How to Recognize It

Before fitting a line, look at the shape of the cloud and at what you will use the line for.

  1. Do the dots form a roughly straight band rather than a bend or a shapeless blob?

    Yes means one straight line can summarize them. If the band bends, as cooling cocoa's temperature does, a line misleads, and the Residuals left over will show a curved shape.

  2. Is the x-value you want a prediction for inside the range of the data?

    Yes is a fair use of the line. A line fitted to children aged 5 to 10 says little about a 30-year-old; going outside the data is extrapolation and cannot be trusted.

  3. Will you draw the line by eye or read it from a given equation, rather than compute it from sums of the data?

    Yes is Line of Best Fit work. If you must calculate b1=r sy/sx and b0=yˉ−b1xˉ from summary statistics, you are doing Linear Regression.

  4. Does the question want a line with a slope and an intercept, not one number for how tightly the dots follow it?

    Yes keeps you on the line. A single unitless value between −1 and 1 is the Correlation Coefficient, which has no slope or intercept to predict with.

Line of Best Fit vs Linear Regression vs Correlation Coefficient vs Residuals

Students often call the trend line, the method that computes it, its strength number and its misses all the regression. Ask whether you need a line, a calculation, one strength number, or one point's gap.

Line of Best Fit

Meaning
A line of best fit is the straight line through a scatter plot that follows the overall trend of the dots, used to summarize it and predict.
Key test
The line itself on the graph, with a slope and an intercept.
Formula
y^=mx+b
Example
Reading the line y^=5x+60 at 3 hours of study predicts a score of 75.

Linear Regression

Meaning
Linear regression is the method that calculates the least-squares line from the data and studies how well it fits.
Key test
Computes the line from the data instead of placing it by eye.
Formula
b1=rsysx,b0=yˉ−b1xˉ
Example
With r=0.8, sy=10 points and sx=2 hours, the slope is b1=4 points per hour.

Correlation Coefficient

Meaning
The correlation coefficient r is a single number from −1 to 1 giving the direction and tightness of a straight-line trend.
Key test
One unitless number; it gives no equation and cannot predict a value.
Formula
r=1n−1∑zxzy
Example
r=0.9 for study hours and scores means the dots hug a rising line closely.

Residuals

Meaning
A residual is the vertical gap between one data point and the line, the actual y minus the predicted y.
Key test
Belongs to one point and measures how far the line missed it.
Formula
e=y−y^
Example
The line predicts 75 for 3 hours, the student scored 81, so the residual is +6.

Formula & Notation

y^=mx+b
The line of best fit minimizes ∑i=1n(yi−y^i)2=∑i=1n(yi−b0−b1xi)2, yielding y^=b0+b1x.

How to read it: y^=b0+b1x is the same line as the formula y^=mx+b, with b1=m and b0=b. b1 (slope) is the change in y per unit change in x. b0 (intercept) is the predicted y when x=0.

Worked Examples

Example 1 — Write the trend line and predict

Easy

Five students' (hours studied, test score) pairs are (1, 62), (2, 68), (3, 71), (4, 77) and (5, 82). A trend line is drawn through (1, 62) and (5, 82). Find its equation, check it, and predict the score for 3.5 hours of study.
Show the steps and the answer
  1. Slope: m=82−625−1=204=5.

    The slope is the rise in score per hour along the line, which is the rate the trend describes.

  2. Intercept: 62=5(1)+b, so b=57 and y^=5x+57.

    Once the slope is known, any point on the line fixes b.

  3. Check against the point of averages: xˉ=3, yˉ=3605=72, and 5(3)+57=72.

    A good trend line passes through (xˉ,yˉ); the exact least-squares line here, y^=4.9x+57.3, does too and is almost the same.

  4. Predict: y^=5(3.5)+57=74.5.

    3.5 hours lies inside the 1 to 5 hour range of the data, so the line's trend is a reasonable guide there.

Answer: y^=5x+57; about 74.5 points for 3.5 hours of study.

Takeaway: Read the slope as a rate (5 points per hour) and predict only inside the range of the data.

Example 2 — A straight line through a curve

Standard

A cup of cocoa's temperature in °C at 0, 5, 10, 15, 20 and 25 minutes is 90, 66, 50, 39, 32 and 27. The least-squares line is y^≈81.2−2.45x. Is a line of best fit a good model here? What does it predict at 40 minutes?
Show the steps and the answer
  1. Look at the drops per 5 minutes: 24, 16, 11, 7, 5 degrees.

    A straight line needs roughly equal drops; these shrink steadily, so the pattern curves.

  2. Compare data with the line: at 0 min the line gives 81.2 (data 8.8 above), at 10 min 56.8 (data 6.8 below), at 25 min 20.1 (data 6.9 above).

    Points above the line at both ends and below it in the middle are the signature of a curve the line cannot follow.

  3. Extrapolate: 81.2−2.45(40)=81.2−98=−16.8 °C.

    Cocoa cannot cool below room temperature, so the prediction is impossible: the line was never valid past the data.

Answer: No. The cooling curve flattens, so the line misses in a systematic pattern and predicts an impossible −17 °C at 40 minutes; the cocoa will level off near room temperature.

Takeaway: Check that the cloud is straight before trusting a trend line, and never extend a line far past the data.

Example 3 — Find the mistake: forced through the origin

Application

Taxi rides of 2, 4, 6, 8 and 10 km cost $7.00, $11.10, $14.90, $19.00 and $23.00. Mia writes: "A 0 km ride should cost nothing, so my line goes through the origin: slope =23/10=2.3, so fare =2.3d." Find the mistake and correct it.
Show the steps and the answer
  1. Test Mia's line: at 2 km it gives 2.3(2)=4.60 dollars against an actual $7.00; at 4 km, 9.20 against $11.10.

    Her line undercharges every short ride by about $2, always in the same direction, so it does not fit the data.

  2. Take the slope from the data: 23.00−7.0010−2=168=2 dollars per km.

    The fares rise by about $4 for every 2 km, wherever you look.

  3. Let the data set the intercept: 7=2(2)+b, so b=3.

    The intercept is a $3 starting charge, which taxis add before the car moves; the data, not a rule about the origin, decide it.

  4. Check: 2d+3 gives 11, 15 and 19 at 4, 6 and 8 km, each within $0.10 of the real fares.

    The least-squares line, y^=1.995d+3.03, is essentially the same, confirming the fix.

Answer: fare≈2d+3: a $3 base charge plus $2 per kilometre.

Takeaway: Do not force a trend line through the origin; let the data choose the intercept and read it as the starting value.

Where You'll See It

  • Predicting score from study hours

    After plotting study hours vs. test scores, the trend line y^=mx+b lets a student plug in 4 hours and predict a likely score — a prediction the scattered dots alone don't give.

  • Plant height over weeks

    A best-fit line through weekly plant-height measurements summarizes the growth rate (the slope) and predicts height for a future week within the measured range.

  • Phone battery drain

    Plotting minutes of use vs. battery percent and fitting a line estimates how fast the battery drops per minute, helping predict when it will hit 20%.

Common Mistakes

  1. The slip: You can use the line to predict far beyond the data you collected.

    Why it's tempting: The line is a formula, so it seems to work for any x you plug in.

    Instead: Predicting outside the range of the data (extrapolation) is unreliable, because the linear trend may not continue. Predict only within the observed x-range.

  2. The slip: A line of best fit is appropriate for any scatter plot.

    Why it's tempting: There's always a 'best' line you can compute, so it feels universally valid.

    Instead: A straight line only fits a roughly linear pattern. If the scatter curves, the line of best fit is the wrong model even though software will still draw one.

  3. The slip: The line should pass through the origin (0,0).

    Why it's tempting: Starting at zero feels natural, especially for 'amount' variables.

    Instead: Let the data set the intercept b. Forcing the line through the origin when the data don't support it distorts both slope and predictions.


Mini Practice

Try these on your own. Tap Reveal when you want to check.

  1. A line of best fit for study time x (hours) and test score y is y^=6x+58. Predict the score for 4.5 hours of study.

    Hint: Substitute the value of x into the equation.

  2. A trend line passes through (2,30) and (10,70). Find its equation.

    Hint: Find the slope first, then use one point to find the intercept.

  3. For outdoor temperature x (°C) and daily heating cost y (dollars), the line of best fit is y^=−0.8x+40. Explain what the slope and the intercept mean.

    Hint: The slope is the change in y for each 1-unit increase in x.

  4. Find the least-squares line for the points (1,2), (2,4), (3,5), (4,4), (5,7).

    Hint: Use the slope ∑(x−xˉ)(y−yˉ)∑(x−xˉ)2, and remember the line passes through (xˉ,yˉ).

  5. A scatter plot of a thrown ball's height over 2 seconds rises and then falls in an arch. Should you draw a line of best fit?

    Hint: Does a straight line follow the shape of the points?

  6. Workers with 1 to 10 years of experience earn from $42k to $78k. Sam forces his line through (0,0) and (10,78) and says, "Pay rises $7.8k per year." Correct him.

    Hint: Would someone with 0 years of experience really earn $0?

Want the full set?

50 practice questions for this concept — free to try, every one with a complete worked solution showing the why, not just the answer.

Frequently Asked Questions

Why square the misses instead of just adding them up?

Plain misses cancel out. Points above the line give positive gaps and points below give negative ones, and every line through the point of averages (xˉ,yˉ)(\bar{x}, \bar{y}) has gaps that add to exactly zero, so adding them cannot pick out one line. Squaring makes every miss count as positive and punishes big misses more than small ones. Adding absolute values also works, but squares lead to simple formulas for the slope and intercept.

Does the line of best fit have to pass through any of the data points?

No, it can miss all of them. For the points (1,1)(1, 1), (2,3)(2, 3) and (3,2)(3, 2), the least-squares line is y^=0.5x+1\hat{y} = 0.5x + 1. It predicts 1.5, 2 and 2.5 at those three xx-values, so it misses every point. What it always passes through is the point of averages, here (2,2)(2, 2), which need not be a data point either.

What does it mean if the line of best fit is flat?

A flat line has slope 0, so it predicts the same value for every xx: the mean of yy. Knowing xx then tells you nothing extra about yy, at least along a straight line, and the correlation is 0. Check the scatter plot before deciding the variables are unrelated, though, because a U-shaped cloud can also produce a flat best-fit line.

Can I use the same line to predict x from y?

Not fairly. The line was chosen to make the vertical misses small, which is the right job when yy is the thing being predicted. To predict hours of study from a test score, you would fit a new line that makes the horizontal misses small, and unless the points lie exactly on a line, it has a different slope. Decide which variable you are predicting before you fit.

Learning Path

← Before

Scatter Plot
Line of Best Fit

You are here

You need Scatter Plot first, since the line is drawn through its cloud of points. The line of best fit adds a rule, y^=mx+b, with a slope you can interpret and an equation you can use for predictions. Next, Linear Regression computes the least-squares line exactly and studies its errors, and the Correlation Coefficient measures how closely the points follow the line.

See Also