Least Squares Regression Line Calculator

Least Squares Regression Line

Fit a best-fit line to a set of x,y data points.

Last updated: June 2026 | By Patchworkr Team

Data Points

Enter at least two points.

Results
Enter at least two valid points to fit the line.

How It Works

The least squares line minimizes squared vertical residuals. The slope and intercept come from the standard closed-form sums over the data points.

Formula

Slope
m = (nΣxy - ΣxΣy) / (nΣx^2 - (Σx)^2)
Intercept
b = (Σy - mΣx) / n

Example

For points 1,2; 2,3; 3,5; 4,4; 5,6 the best-fit line is approximately y = 1.1x + 0.5.

FAQ

Can I enter invalid lines?

No. Each non-empty line must be a valid x,y pair.

How many points do I need?

At least two points are required.

What if all x-values are equal?

Regression is undefined because the denominator becomes zero.

Does blank input count as zero?

No. Blank input is treated as missing, not zero.

Related Tools