Line of Best Fit

A line of best fit is a straight line drawn through the middle of the points on a scatter plot. It shows the overall trend of the data. You can write its equation in slope-intercept form, y = mx + b, and use it to make predictions. It is also called a trend line or line of fit.

Before this lesson: You should know scatter plots and correlation, slope-intercept form and writing equations in slope-intercept form.

What Is a Line of Best Fit?

Real data almost never falls exactly on a line. But when a scatter plot shows a linear pattern, one line can sum it up. That line is the line of best fit.

Here is the study-time data from the last lesson. The line runs through the middle of the cloud, with some points above it and some below.

Hours studied1223445667
Quiz score62657072758084859092
A scatter plot of 10 students, with hours studied from 0 to 8 on the x-axis and quiz score from 50 to 100 on the y-axis. The points rise from left to right. A green line of best fit, y = 5.06x + 57.28, runs through the middle of the points. An orange bracket at 4 hours shows the residual from the point (4, 80) down to the line at about 77.5.
The line of best fit runs through the middle of the points. The point (4, 80) is about 2.5 points above the line.

How to Find a Line of Best Fit

By eye

  1. Make a scatter plot and check that the pattern looks linear.
  2. Draw a straight line through the middle of the points. Try to have about as many points above it as below.
  3. Pick two points on your line. They don’t have to be data points.
  4. Find the slope: m = \frac{y_2 - y_1}{x_2 - x_1}.
  5. Use one point to find b, and write y = mx + b.

With a calculator

A graphing calculator or app can find the exact line of best fit. This is called linear regression. For the study data, it gives y = 5.06x + 57.28 with r \approx 0.98.

What the slope and y-intercept mean

The slope is the rate of change. Here, each extra hour of study goes with about 5 more points on the quiz. The y-intercept, 57.28, is the predicted score for 0 hours of study.

Worked Examples

Example 1: Write an equation for a line drawn by eye

A student draws a line of fit for the study data. It passes through (1, 62) and (7, 92). Write its equation.

\begin{aligned} m &= \frac{92 - 62}{7 - 1} = \frac{30}{6} = 5 \\ 62 &= 5(1) + b \\ b &= 57 \end{aligned}

The equation is y = 5x + 57. It is very close to the calculator’s line.

Example 2: Interpret the slope and y-intercept

Use y = 5.06x + 57.28. What do 5.06 and 57.28 mean?

The slope 5.06 means each extra hour of study goes with about 5.06 more points. The y-intercept 57.28 means a student who studies 0 hours is predicted to score about 57.

Example 3: Make a prediction

Predict the score for a student who studies 5.5 hours.

y = 5.06(5.5) + 57.28 = 27.83 + 57.28 = 85.11

The predicted score is about 85.

Example 4: Find a residual

A residual is the actual value minus the predicted value. Find the residual for the point (4, 80).

\begin{aligned} \text{predicted} &= 5.06(4) + 57.28 = 77.52 \\ \text{residual} &= 80 - 77.52 = 2.48 \end{aligned}

The residual is about 2.5. It is positive, so the point is above the line. For (4, 75), the residual is 75 - 77.52 = -2.52, so that point is below the line.

Example 5: When not to trust a prediction

Use the line to predict the score for 10 hours of study.

y = 5.06(10) + 57.28 = 107.88

A quiz score can’t be more than 100. The data only goes up to 7 hours, so the line may not hold at 10 hours. Predicting far outside the data is called extrapolation, and it can be wrong. Predicting inside the data is safer.

Common Mistakes

MistakeExample of the errorFix
Joining the first and last pointsDrawing the line from the lowest point to the highestGo through the middle of all the points, with about as many above as below.
Trying to hit every pointBending the line to touch each dotA line of best fit is straight. Most points will be off the line.
Residual with the wrong signResidual = predicted − actualResidual = actual − predicted. A positive residual means the point is above the line.
Trusting predictions far from the dataPredicting a quiz score of 108Only predict inside or close to the data’s range.
Mixing up slope and rSaying the slope is 0.98r shows how strong the fit is. The slope is the rate of change, here 5.06.

Practice Problems

Problems 1 to 7 use this data. A café records the outside temperature (°F) and cups of hot cocoa sold.

Temperature (°F)40455055606570
Cups sold50474037302720
  1. What type of correlation does the data show?
  2. A line of fit passes through (40, 51) and (70, 21). Write its equation.
  3. What does the slope of your line mean?
  4. Use your line to predict cups sold at 58°F.
  5. Find the residual for the point (50, 40) using your line.
  6. A calculator gives y = -1.00x + 90.86. Use it to predict cups sold at 62°F.
  7. Would it make sense to use the line to predict sales at 100°F? Explain.
  8. Line A has residuals 3, −2 and 1. Line B has residuals 6, −5 and 4 for the same points. Which line fits better?
  9. For the study data, what does the y-intercept of y = 5x + 57 mean?
Show answers
  1. A strong negative correlation. As the temperature goes up, cocoa sales go down.
  2. m = \frac{21 - 51}{70 - 40} = \frac{-30}{30} = -1. Then 51 = -1(40) + b, so b = 91. The line is y = -x + 91.
  3. For each 1°F warmer, the café sells about 1 fewer cup of cocoa.
  4. y = -58 + 91 = 33 cups.
  5. Predicted: -50 + 91 = 41. Residual: 40 - 41 = -1. The point is 1 cup below the line.
  6. y = -1.00(62) + 90.86 = 28.86, so about 29 cups.
  7. No. The line gives y = -100 + 91 = -9, and you can’t sell a negative number of cups. 100°F is far outside the data, so this is extrapolation.
  8. Line A, because its residuals are smaller. Its points are closer to the line.
  9. A student who studies 0 hours is predicted to score 57.

FAQ

How do you find the line of best fit?

Draw a line through the middle of the points, then use two points on it to find the slope and y-intercept. For an exact line, use linear regression on a calculator.

What is the difference between a line of best fit and linear regression?

Linear regression is a method for finding the line of best fit. It finds the line that keeps the residuals as small as possible.

What is a residual?

It is the actual y-value minus the predicted y-value. Positive residuals are above the line, and negative ones are below it.

Can a line of best fit go through none of the points?

Yes. It only needs to follow the overall trend. It may pass through some points, or none at all.

Summary

  • A line of best fit shows the trend in a scatter plot.
  • Draw it through the middle of the points, or use linear regression.
  • Write it as y = mx + b. The slope is the rate of change.
  • A residual is actual minus predicted.
  • Predictions are best inside the range of the data.

Previous lesson: Scatter Plots and Correlation

Next course: Geometry Index

Back to the Algebra 1 Index