Linear regression calculator
Fit a straight line through paired data and see how well it fits. Students, scientists and analysts use it for lab data, trends and quick forecasts.
- Runs in your browser
- Free, no account needed
- Copy or download the result
Result
The short answer
Least squares regression finds the straight line y = mx + b that makes the sum of squared vertical gaps to your points as small as possible. R squared tells you how much of the variation in y the line explains.
Formulaslope m = sum((x - mean x)(y - mean y)) / sum((x - mean x)^2); intercept b = mean y - m x mean x
Worked exampleFor the six points (1, 52), (2, 58), (3, 63), (4, 71), (5, 75) and (6, 82) the line is y = 5.97143x + 45.9333 with r = 0.997749 and R squared = 0.995503, and at x = 8 it predicts y = 93.7048.
Example
1, 52 2, 58 3, 63 4, 71 5, 75 6, 82
- Predicted y at x 8
- 93.7048
- Slope
- 5.97142857143
- Intercept
- 45.9333333333
- Correlation r
- 0.997749
- R squared
- 0.995503
- Points
- 6
- Mean x
- 3.5
- Mean y
- 66.8333333333
The equation and prediction are rounded to 6 significant digits; slope and intercept show 12.
How to use the linear regression calculator
- Enter x and y for each point in the rows, or type pairs such as 3, 63 one per line.
- Optionally fill in Predict y at x.
- The equation appears first, then the prediction, slope, intercept, r and r squared. Results update as you type, and Run also works.
- Press Copy result or Download to keep the results.
How it works
The line is the ordinary least squares fit: slope = sum of (x - mean x)(y - mean y) / sum of (x - mean x)², and intercept = mean y - slope x mean x.
r is the Pearson correlation coefficient, and r squared is the share of the variation in y that the line explains.
Each line needs exactly two numbers separated by a comma, semicolon, tab or space. At least two different x values are required, and up to 5,000 pairs are allowed.
If every y value is the same, r and r squared are reported as not defined. The equation and prediction are rounded to 6 significant digits, and slope and intercept to 12.
Everything runs in your browser. Your input is not uploaded or stored. If you use Copy link, what you entered is placed in the link.
Questions and answers
What is a line of best fit?
It is the straight line that makes the sum of squared vertical distances from the points to the line as small as possible.
What is the difference between r and r squared?
r shows the direction and strength of a straight line relationship, from -1 to 1. r squared is r times r and tells you the share of variation explained.
Can I use it to predict values?
Yes. Enter an x in Predict y at x. Predictions far outside your data range are less reliable.
Last updated November 1, 2026. Maintained by SnowRock. How our tools work
All 220 SnowRock tools