Line of Best Fit

A line that best approximates scattered data points, used to predict values and identify trends in relationships between two variables.

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

Solve a problem with Line of Best Fit

Type the problem. The solver will use Line of Best Fit where Line of Best Fit is the right tool, and tell you when it is not.

Drag one in or paste from the clipboard. JPEG, PNG or WebP. You get the transcription to check before anything is solved.

How to get a better answer
  • Paste the whole problem, including the instruction word — "simplify", "solve for x" and "factor" lead to three different answers.
  • Say what you have already tried. "I got x = 4 and the book says 2" turns a solution into a diagnosis.
  • Set the level in the settings button. A calculus shortcut is not a better answer if you have not met derivatives yet.
  • For a photo, get the whole problem in frame and hold the page flat — you get the transcription to fix before anything is solved.

What each symbol means

What Line of Best Fit takes
mm
bb
xx
y^\hat{y}
Line of Best Fit
SymbolMeaning
mmThe slope of the line, representing the rate of change — how much y^\hat{y} increases for each unit increase in xx; its units are the ratio of the yy-units to the xx-units, and confusing it with bb misplaces the line's starting point and tilt.
bbThe yy-intercept, the value of y^\hat{y} when x=0x = 0 where the line crosses the yy-axis; it has the same units as the measured yy-values, and misreading it as a slope or the xx-intercept breaks the equation.
xxThe independent variable, the input quantity or measurement you use to predict (such as temperature, time, or distance); its units depend on the context, and swapping xx with yy reverses which variable is predicted.
y^\hat{y}The predicted or fitted yy-value from the line of best fit at a given xx; it has the same units as the observed yy-values, and confusing it with actual measured yy hides how well the line fits and obscures prediction error.

When to use it

When you have two variables with scattered data and want to find a linear equation that predicts one from the other.

Level

Usually taught in: Algebra I · Appears on: SAT

Worked examples

1. Finding the line through three collinear points

Problem

Find the line of best fit for the points (1,2)(1, 2), (2,4)(2, 4), and (3,6)(3, 6).
  1. m=4221=21=2m = \frac{4 - 2}{2 - 1} = \frac{2}{1} = 2

    Calculate the slope using the first two points: rise over run is ΔyΔx=4221=2\frac{\Delta y}{\Delta x} = \frac{4-2}{2-1} = 2.

  2. y2=2(x1)y - 2 = 2(x - 1)

    Use point-slope form yy1=m(xx1)y - y_1 = m(x - x_1) with point (1,2)(1, 2) and slope m=2m = 2.

  3. y2=2x2y - 2 = 2x - 2

    Distribute the slope 22 into (x1)(x - 1): 2x=2x2 \cdot x = 2x and 2(1)=22 \cdot (-1) = -2.

  4. y=2xy = 2x

    Add 22 to both sides to isolate yy and write in slope-intercept form: y^=2x+0\hat{y} = 2x + 0.

  5. Check:  y^(3)=2(3)=6\text{Check:} \; \hat{y}(3) = 2(3) = 6 \checkmark

    Verify with the third point: when x=3x = 3, the line predicts y^=6\hat{y} = 6, which matches the data.

Answer: y^=2x\hat{y} = 2x

Since all three points lie exactly on one line, any two points give the true relationship. The slope m=2m = 2 means for every 1-unit increase in xx, yy increases by 2 units; the line passes through the origin (b=0b = 0).

2. Line of best fit using point-slope form

Problem

Find the line of best fit for the points (1,3)(1, 3), (2,5)(2, 5), (3,6)(3, 6), and (4,8)(4, 8) using the first and last points to estimate the line.
  1. m=8341=53m = \frac{8 - 3}{4 - 1} = \frac{5}{3}

    Calculate slope using the endpoints (1,3)(1, 3) and (4,8)(4, 8): m=change in ychange in x=53m = \frac{\text{change in } y}{\text{change in } x} = \frac{5}{3}.

  2. y3=53(x1)y - 3 = \frac{5}{3}(x - 1)

    Write point-slope form yy1=m(xx1)y - y_1 = m(x - x_1) using (1,3)(1, 3) as the point and m=53m = \frac{5}{3} as the slope.

  3. y3=53x53y - 3 = \frac{5}{3}x - \frac{5}{3}

    Distribute 53\frac{5}{3} across (x1)(x - 1): 53x=53x\frac{5}{3} \cdot x = \frac{5}{3}x and 53(1)=53\frac{5}{3} \cdot (-1) = -\frac{5}{3}.

  4. y=53x53+3y = \frac{5}{3}x - \frac{5}{3} + 3

    Add 33 to both sides to isolate yy.

  5. y=53x+43y = \frac{5}{3}x + \frac{4}{3}

    Simplify 53+3=53+93=43-\frac{5}{3} + 3 = -\frac{5}{3} + \frac{9}{3} = \frac{4}{3}.

Answer: y^=53x+43\hat{y} = \frac{5}{3}x + \frac{4}{3}

When data does not all lie on one line, pick two representative points (often the extremes or points on the trend) to calculate mm and bb. The points (2,5)(2, 5) and (3,6)(3, 6) deviate slightly from this line, which is expected — the line of best fit balances these deviations.

3. Word problem: predicting coffee shop sales from temperature

Problem

A coffee shop records temperature and drink sales. On a 65°F65°\text{F} day they sold 5050 drinks, at 75°F75°\text{F} they sold 7575 drinks, and at 85°F85°\text{F} they sold 100100 drinks. Find the line of best fit and predict sales at 72°F72°\text{F}.
  1. m=75507565=2510=2.5m = \frac{75 - 50}{75 - 65} = \frac{25}{10} = 2.5

    Calculate slope using the first two data points (65,50)(65, 50) and (75,75)(75, 75): each 10°F10°\text{F} increase predicts a 2525-drink increase.

  2. y50=2.5(x65)y - 50 = 2.5(x - 65)

    Use point-slope form yy1=m(xx1)y - y_1 = m(x - x_1) with point (65,50)(65, 50) (temperature =65= 65, sales =50= 50) and slope m=2.5m = 2.5.

  3. y50=2.5x162.5y - 50 = 2.5x - 162.5

    Distribute 2.52.5 across (x65)(x - 65): 2.5×65=162.52.5 \times 65 = 162.5.

  4. y=2.5x112.5y = 2.5x - 112.5

    Add 5050 to both sides: 162.5+50=112.5-162.5 + 50 = -112.5.

  5. Verify:  y^(85)=2.5(85)112.5=212.5112.5=100\text{Verify:} \; \hat{y}(85) = 2.5(85) - 112.5 = 212.5 - 112.5 = 100 \checkmark

    Check with the third point: at x=85°Fx = 85°\text{F}, the line predicts 100100 drinks, matching the data.

  6. y^(72)=2.5(72)112.5=180112.5=67.5\hat{y}(72) = 2.5(72) - 112.5 = 180 - 112.5 = 67.5

    Predict sales at 72°F72°\text{F} by substituting x=72x = 72 into the equation: the line predicts about 67676868 drinks.

Answer: y^=2.5x112.5;  at 72°F, predicted sales67.5 drinks\hat{y} = 2.5x - 112.5; \; \text{at } 72°\text{F}, \text{ predicted sales} \approx 67.5 \text{ drinks}

This word problem ties the abstract symbols to real quantities: xx is temperature in °F°\text{F} and y^\hat{y} is predicted drink sales. The negative yy-intercept (b=112.5b = -112.5) is not physically meaningful at 0°F0°\text{F} (you cannot have negative sales), but it is mathematically correct within the range of observed data — a reminder that models apply only where data supports them.

Common mistakes

Where Line of Best Fit usually goes wrong
Answer came out wrong
Confusing y^\hat{y} (predicted value from the line) with yy (actual measured data value), or assuming they must be equal.
Remember that y^\hat{y} is what the line says yy should be, while yy is what was actually measured — they are almost never identical. Compute residuals as yy^y - \hat{y} to see how far each point is from the line.
Insisting that the line of best fit must pass through every single data point.
Accept that the line balances residuals — some points will be above and some below it. If you feel tempted to connect every point with a jagged path, you do not have a line of best fit; you have a polygon through the data.
Using the line of best fit to predict far outside the range of your data (e.g., predicting sales at a temperature when you have never collected data near that temperature).
Interpolate (predict within your data range) freely, but extrapolate (predict outside) cautiously and only when you have a strong reason to believe the line continues beyond your observations.
The mistakeWhy it is wrongThe fix
Confusing y^\hat{y} (predicted value from the line) with yy (actual measured data value), or assuming they must be equal.The line of best fit predicts values y^\hat{y} that usually do not match the actual measured yy exactly; the difference is called a residual, and it shows how well the line fits the data.Remember that y^\hat{y} is what the line says yy should be, while yy is what was actually measured — they are almost never identical. Compute residuals as yy^y - \hat{y} to see how far each point is from the line.
Insisting that the line of best fit must pass through every single data point.A line of best fit minimizes overall error across all points; some points will lie above the line and others below, and forcing the line through every point is impossible unless the data is perfectly linear and requires no fitting.Accept that the line balances residuals — some points will be above and some below it. If you feel tempted to connect every point with a jagged path, you do not have a line of best fit; you have a polygon through the data.
Using the line of best fit to predict far outside the range of your data (e.g., predicting sales at a temperature when you have never collected data near that temperature).The linear relationship is only supported by evidence within your data range; beyond that, the relationship may change (the shop may close in winter, or sales may plateau in summer) and the line no longer applies.Interpolate (predict within your data range) freely, but extrapolate (predict outside) cautiously and only when you have a strong reason to believe the line continues beyond your observations.

Tips and when to use something else

  • Slope-intercept form y^=mx+b\hat{y} = mx + b makes both the slope (rate of change) and yy-intercept (starting value) immediately visible — prefer it to standard form when working with line of best fit.
  • If your data is scattered, pick two points that seem most representative of the trend (often the endpoints or points closest to the overall pattern) and use them to calculate mm and bb — you do not have to use only data points.
  • If your yy-intercept bb is large, negative, or unexpected, verify by checking that y^\hat{y} gives a reasonable value at one of your original data points; arithmetic errors are common when bb is messy.
  • Distinguish between linear and nonlinear relationships: if your points curve or bend rather than following a straight path, a parabola y=ax2+bx+cy = ax^2 + bx + c or other model may fit better than a line of best fit.

Frequently asked questions

What is the difference between line of best fit and slope-intercept form?
Slope-intercept form y=mx+by = mx + b is the equation template. A line of best fit is the specific line you fit to your data using that template — it is the unique linear equation that minimizes error across your data points. Not all equations in slope-intercept form are lines of best fit; only one is the best fit for your particular dataset.
How do I know if my line of best fit is good?
Look at how close the data points are to the line (the distances are called residuals). If points cluster tightly around the line, the fit is good. If they are far away or follow a curved pattern instead of a straight one, the fit is poor and linear may not be the right model for your data.
Can the line of best fit have a yy-intercept of zero?
Yes, if the data supports it. If your points suggest a yy-intercept of b=0b = 0, then your line is y^=mx\hat{y} = mx and passes through the origin. However, do not force b=0b = 0 unless the data itself clearly shows the line passes through the origin; let the data determine bb.
Do I have to memorize the least-squares formula to find a line of best fit?
No. For most Algebra I and SAT problems, you can find the line by selecting two representative points from your data and calculating the slope and intercept from them using point-slope form. The least-squares method is more precise for advanced courses, but the point-selection method works well for typical high-school problems.

Need a different method?

The full solver is not scoped to one formula — type any problem and it will pick the method.

Open the math solver

Reviewed 2026-09-18