Linear Regression Calculator
Fit y = mx + b to paired data by ordinary least squares. Get slope, intercept, r², residuals and a scatter plot with the best-fit line drawn on canvas.
Best-fit line: ŷ = 0.6x + 2.2
Predict ŷ for an x value
This x is outside your data range (1 to 5) — extrapolated predictions are less reliable.
Residuals (y − ŷ)
| x | y | ŷ | Residual |
|---|---|---|---|
| 1 | 2 | 2.8 | -0.8 |
| 2 | 4 | 3.4 | 0.6 |
| 3 | 5 | 4 | 1 |
| 4 | 4 | 4.6 | -0.6 |
| 5 | 5 | 5.2 | -0.2 |
What is the Linear Regression Calculator?
The ByteTools Linear Regression Calculator fits a straight line y = mx + b to paired x/y data using ordinary least squares: the slope is m = Sxy / Sxx and the intercept is b = ȳ − m·x̄.
- Ordinary least squares fit: slope, intercept and equation
- r and r² goodness-of-fit statistics
- Residual table for every data point
- Canvas scatter plot with best-fit line, axes and gridlines
- Prediction box for any x value
- PNG chart download — all 100% in-browser
How to use the Linear Regression Calculator
- 1
Enter your data as one x, y pair per line (comma, space or tab separated).
- 2
Read the fitted equation y = mx + b, plus r and r².
- 3
Inspect the scatter plot and best-fit line on the chart.
- 4
Enter any x value to predict ŷ from the fitted line.
- 5
Download the chart as a PNG or copy the numeric summary.
About the Linear Regression Calculator
The ByteTools Linear Regression Calculator fits a straight line y = mx + b to paired x/y data using ordinary least squares: the slope is m = Sxy / Sxx and the intercept is b = ȳ − m·x̄. You get the fitted equation, the correlation coefficient r, the coefficient of determination r², and a residual for every point.
A scatter plot with the best-fit line is drawn directly on an HTML canvas — axes, ticks and gridlines included — so you can see at a glance how well the line describes your data. A prediction box lets you plug any x into the fitted equation, and the chart can be downloaded as a PNG.
Everything runs 100% locally in your browser: paste pairs from a spreadsheet, and neither your data nor the chart ever leaves your device. Ideal for statistics coursework, lab reports and quick trend checks.
Frequently asked questions
How is the line of best fit calculated?
By ordinary least squares, which minimises the sum of squared vertical distances from the points to the line. The slope is m = Σ(x−x̄)(y−ȳ) / Σ(x−x̄)² and the intercept is b = ȳ − m·x̄. For x = 1…5, y = 2, 4, 5, 4, 5 the fit is y = 0.6x + 2.2.
What does r² tell me about the regression?
r² is the fraction of the variation in y explained by the linear relationship with x. r² = 0.9 means 90% of the variability follows the line; r² near 0 means the line explains almost nothing. It does not prove the relationship is linear — always look at the scatter plot.
What is a residual?
A residual is the vertical gap between an observed point and the fitted line: residual = y − ŷ. Small, randomly scattered residuals suggest a good linear fit, while a curved pattern in the residuals signals that a straight line is the wrong model.
How many data points do I need for linear regression?
Mathematically two points define a line, but a meaningful fit needs more — this tool requires at least 3 pairs and statisticians usually want 10 or more before trusting slope estimates. More points make the slope, intercept and r² far more stable.
Can I use the regression line to predict beyond my data range?
You can, but extrapolation is risky: the linear pattern may not continue outside the observed x range. Predictions inside the data range (interpolation) are much more reliable. The tool flags predictions that fall outside your data's x range.
Related tools
Correlation Coefficient Calculator
Calculate Pearson's correlation coefficient r and r² for paired x, y data. Get a plain-English read of the strength and direction of the linear relationship.
Slope Intercept Form Calculator
Find the equation of a line from two points or from a slope and a point. Get y = mx + b, point-slope and standard form, plus a drawn line graph.
Standard Deviation Calculator
Calculate population and sample standard deviation and variance from a list of numbers. Free online tool showing the mean, count and formula steps.
Variance Calculator
Calculate population and sample variance from a list of numbers. See the mean, squared deviation table and standard deviation, computed in your browser.
Mean, Median & Mode Calculator
Calculate the mean, median, mode, range, sum and count from a list of numbers. Handles no-mode and multi-modal data, all computed privately in your browser.