Line of Best Fit: Definition, Method and Examples

MathPublished

Line of Best Fit: Definition, Method and Examples

A line of best fit is a straight trend line that represents the overall direction of points on a scatter plot. It balances the data with a similar spread of points on either side, allowing you to model relationships and make reliable mathematical estimates.

What is a line of best fit?

In statistics, when you plot bivariate data on scatter plots, the points often show a general direction. A line of best fit, sometimes called a trend line, is a straight line drawn through the center of these points to model their relationship.


A scatter plot showing an upward-sloping straight line passing through the center of a group of data points.


The line of best fit models the trend of the data but does not need to pass through every point.


The most accurate mathematical line is calculated using a method called least squares regression. This procedure ensures the line is perfectly balanced by minimizing the total vertical distance between the line itself and all the data points.

Decide when a line is appropriate

You should only draw a straight line of best fit when the data points show a clear linear pattern.


There must be a visible correlation where the coordinates group reasonably close to a straight path. If the points form a distinct curve or are scattered randomly with no recognizable pattern, a straight line is not appropriate and will produce false estimates.

Three scatter plots side-by-side. The first shows a linear trend. The second shows a non-linear curve. The third shows scattered points with no correlation.

Check the data carefully before relying on a trend line. If a straight line does not genuinely capture the relationship, do not draw one.

Draw a balanced trend line

You can estimate a line of best fit visually, or you can calculate its exact position using the mathematical least squares method.


When drawing a trend line visually by eye, follow these three guidelines:

  1. Follow the general slope and direction of the points.
  2. Keep roughly the same number of points above the line as below the line.
  3. Position the line so it passes through the center of the densest clusters.

To eliminate guesswork, mathematicians use the least squares regression method. This calculates the exact equation of the line, structured as y=mx+by = mx + b.


A scatter plot showing a trend line with dashed red vertical segments connecting each data point to the line, representing the errors being minimized.

The method minimizes the vertical errors between the points and the line. It uses all NN coordinates in the dataset to calculate the slope (mm) and the y-intercept (bb) with these formulas:

m=N∑(xy)−∑x∑yN∑(x2)−(∑x)2m = \dfrac{N \sum (xy) - \sum x \sum y}{N \sum (x^2) - (\sum x)^2}


b=∑y−m∑xNb = \dfrac{\sum y - m \sum x}{N}

Note the important difference in the denominator of the slope formula: ∑(x2)\sum (x^2) means you square each xx-value first and then add them, while (∑x)2(\sum x)^2 means you add all the xx-values first and then square the final total.

Handle outliers

An outlier is a data point that lies far away from the main cluster and does not follow the general pattern of the relationship.


Because the least squares method tries to balance the distance to every single point, outliers can severely warp the calculated line. An extreme outlier acts like a magnet, pulling the line of best fit away from the true trend of the majority data.

A scatter plot comparing two lines. A solid blue line models the main cluster correctly. A dashed red line is tilted away from the main cluster because it is pulled toward a single outlier far below.

When constructing a trend line, consider whether the outlier is a genuine measurement error that should be discarded or a rare exception worth investigating. If you draw the line by eye, generally ignore isolated outliers to ensure the line represents the core trend.

Read an estimate from the line

Once a line of best fit is established, you can use it to estimate values that were not measured in your original data.You can find an estimate visually by finding an xx-value on the horizontal axis, moving straight up to the trend line, and reading directly across to the corresponding yy-value on the vertical axis.


Alternatively, you can use the algebraic equation of the line. This is mathematically identical to substituting a known value into other linear equations to solve for an unknown variable.


Predicting a value within the range of your actual gathered data points is generally reliable.


However, extending the line to predict values far beyond your highest or lowest observed measurements leads to interpolation and extrapolation errors. The further you predict outside your data range, the less reliable the estimate becomes, because the real-world relationship might eventually change direction or curve. Understanding these limits is an essential skill when interpreting data graphs.

Worked examples

These examples show how to calculate the least squares formula and use the resulting equation for estimation.


Example 1: Calculating the exact line


Question: Four data points are recorded at (1,2)(1, 2), (2,3)(2, 3), (3,3)(3, 3), and (4,6)(4, 6). Find the exact mathematical line of best fit using the least squares formulas.


Method:

  1. Create a table to find the necessary totals for xx, yy, x2x^2, and xyxy.

The xx-values are 1,2,3,41, 2, 3, 4, so ∑x=10\sum x = 10.

The yy-values are 2,3,3,62, 3, 3, 6, so ∑y=14\sum y = 14.

The squared xx-values (x2x^2) are 1,4,9,161, 4, 9, 16, so ∑(x2)=30\sum (x^2) = 30.

The products (xyxy) are (1×2),(2×3),(3×3),(4×6)(1 \times 2), (2 \times 3), (3 \times 3), (4 \times 6), which equal 2,6,9,242, 6, 9, 24. Their sum is ∑(xy)=41\sum (xy) = 41.


  1. Count the number of coordinate pairs to find N=4N = 4.

  2. Substitute these values into the slope formula for mm.

m=4(41)−(10)(14)4(30)−(10)2m = \dfrac{4(41) - (10)(14)}{4(30) - (10)^2}

m=164−140120−100=2420=1.2m = \dfrac{164 - 140}{120 - 100} = \dfrac{24}{20} = 1.2

  1. Substitute mm and the sums into the y-intercept formula for bb.

b=14−1.2(10)4b = \dfrac{14 - 1.2(10)}{4}


b=14−124=24=0.5b = \dfrac{14 - 12}{4} = \dfrac{2}{4} = 0.5

Answer: The equation for the line of best fit is y=1.2x+0.5y = 1.2x + 0.5.


Check: Test a central xx-value. If x=2x = 2, then y=1.2(2)+0.5=2.9y = 1.2(2) + 0.5 = 2.9. This prediction is extremely close to the actual measured value of 33 at that coordinate, confirming the regression line is balanced.


Example 2: Reading an estimate algebraically


Question: Using the line of best fit y=1.2x+0.5y = 1.2x + 0.5, estimate the value of yy when x=2.5x = 2.5.


Method:

  1. Identify the given value: x=2.5x = 2.5.

  2. Substitute this value into the line's equation.

y=1.2(2.5)+0.5y = 1.2(2.5) + 0.5

  1. Perform the multiplication.

y=3.0+0.5y = 3.0 + 0.5

  1. Complete the addition.

Answer: The estimated value is y=3.5y = 3.5.


Check: The value x=2.5x = 2.5 sits perfectly in the middle of our data range. The predicted answer of 3.53.5 fits logically within the upward trend of our observed yy-values, which grew from 22 to 66.

Common mistakes

Avoid these frequent errors when placing a visual trend line on a scatter plot.

  • Forcing the line through the origin: A common error is assuming the line must begin at (0,0)(0,0). The line should follow the data naturally, and its true y-intercept may be positive or negative.
  • Connecting the first and last points: The line of best fit must represent the entire dataset, not just the extremes. Drawing a line strictly from the first dot to the last dot often ignores the heavily concentrated center of the data.
  • Ignoring the balance: Drawing a line with all the points sitting exclusively above it or exclusively below it completely fails to represent the center of the relationship.

Frequently asked questions

Here are clear answers to common questions about working with lines of best fit.


Does the line of best fit have to touch any actual data points?

No. The line can pass exactly through several points, just one point, or no points at all. Its purpose is to show the average geometric trend, not to trace or connect specific measurements.


Can a line of best fit be curved?

When data points clearly follow a curving path, you can model them with a curve of best fit. However, the specific mathematical term "line of best fit" always refers to a straight, linear model.


What does it mean if the line goes downward?

A downward-sloping line indicates a negative correlation. This means that as the independent variable on the x-axis increases, the dependent variable on the y-axis tends to decrease.

Practice questions

Question

A scatter plot with data points trending upwards. A straight trend line is drawn completely flat near the bottom, with all data points sitting far above it.


What is the main mathematical problem with the proposed trend line shown in the diagram?

  • All the data points lie above the line.

  • It does not pass through the origin.

  • It ignores a distant outlier.

  • It does not connect the first and last points.

Answer:

All the data points lie above the line.

Question

A student calculates the least squares regression line for a dataset. Which statement describes the primary goal of this exact mathematical method?

  • To connect the maximum possible number of data points.

  • To minimize the vertical distance between the points and the line.

  • To guarantee the line will pass through the origin.

  • To remove all outliers from the original dataset automatically.

Answer:

To minimize the vertical distance between the points and the line.

Question

If a single extreme outlier is added to a scatter plot far above the main cluster of points, what will generally happen to the calculated line of best fit?

  • The line will tilt or shift upward toward the outlier.

  • The line will shift downward, moving away from the outlier.

  • The line will remain exactly the same as before.

  • The straight line will curve to pass through the outlier.

Answer:

The line will tilt or shift upward toward the outlier.

Question

The exact line of best fit for a set of scientific data is determined to be y=3x+12y = 3x + 12. What is the estimated value of yy when x=5x = 5?

  • 1515

  • 2020

  • 2727

  • 3232

Answer:

2727

Question

Why is it mathematically risky to use a line of best fit to predict values far beyond the range of your actual measured data?

  • The relationship between the variables might eventually change direction or curve.

  • The line will automatically curve back to zero once it leaves the graph.

  • The linear equation formula stops working for very large numbers.

  • The slope of the line always reverses sign past the final point.

Answer:

The relationship between the variables might eventually change direction or curve.