Linear Regression Calculator: Line of Best Fit
Use this linear regression calculator to find the line of best fit for your data. Paste x and y values, and get the slope, intercept, equation and R squared, with a scatter chart. Use it to predict y for any x value.
Linear Regression Calculator
Least-squares line of best fit.
How to use the Linear Regression Calculator
- Paste your data, one x, y pair per line.
- Read the regression equation.
- Check R² to see how well the line fits.
- Enter an x value to predict y.
How it works
Ordinary least squares picks the line that minimizes the sum of squared vertical distances to the points. The slope is b = Σ(x−x̄)(y−ȳ) ÷ Σ(x−x̄)² and the intercept is a = ȳ − b·x̄.
Example
For the sample data the line is ŷ = 1.97x + 0.09 with R² = 0.9977, so at x = 6 the prediction is 11.91.
Frequently asked questions
What does R² mean?
The share of the variation in y explained by the line, from 0 to 1.
Is it safe to predict far outside my data?
No. Extrapolation can be very wrong.
Is this the same as Excel LINEST?
Yes, for a simple one-variable line.
See also: Slope Calculator, Statistics Calculator.
Find the line of best fit
How to use it
- Paste x values.
- Paste y values.
- Read the equation and R squared.
- Predict new values.
More questions
What does R squared mean?
How much of the change in y the line explains, from 0 to 1.
Can I paste from a spreadsheet?
Yes. Paste two columns, x and y, straight from your spreadsheet.
What is the slope?
How much y changes when x goes up by one.
Related tools: Correlation Coefficient Calculator, Percentile Calculator, Average Calculator.
Predicting week 6 from five weeks of sales
Paste one x, y pair per line, set an x value to predict and read the slope, intercept, R² and the predicted y. For the spread of the y values on their own, use the Standard Deviation Calculator.
Worked example: weekly sales for weeks 1 to 5 are 52, 58, 61, 67 and 72 units. The line is ŷ = 4.9x + 47.3 with R² = 0.9921. Predicting week 6 gives 4.9 × 6 + 47.3 = 76.7 units.
More answers
What does the intercept 47.3 mean here?
It is the predicted value when x is 0. In this example that would be sales at week 0, which is just a starting point for the line, not a real measured week.
Does a high R² show that one thing causes the other?
No. R² = 0.9921 only says the line fits these five points closely. It does not prove cause, and a trend can stop holding outside the range you measured.