Linear Regression Calculator

Find the line of best fit for your data — enter x and y points to get the slope, intercept and the equation y = mx + b, plus the r² goodness of fit.

How to calculate linear regression

Linear regression finds the straight line that best fits a set of points — the least-squares line y = mx + b. The slope and intercept come from sums across your data: the x, y, xy and x² totals. Enter your x,y points above (one pair per line) and the calculator returns the equation, the slope and intercept, and the r² that tells you how well the line fits.

m = (nΣxy − ΣxΣy) ÷ (nΣx² − (Σx)²),  b = (Σy − mΣx) ÷ n

The slope (m) is how much y changes per one-unit rise in x; the intercept (b) is the predicted y when x = 0. Once you have the line you can predict y for any new x.

What r² tells you

R² (the coefficient of determination) ranges from 0 to 1 and is the share of the variation in y that the line explains. An r² near 1 means a tight fit; near 0 means the line explains little. Always look at r² alongside the equation — a line can be computed for any data, but only a high r² means it predicts well. Need the spread of a single variable instead? Use the variance calculator.

Frequently asked questions

How do I calculate linear regression?

The least-squares line y = mx + b has slope m = (nΣxy − ΣxΣy) ÷ (nΣx² − (Σx)²) and intercept b = (Σy − mΣx) ÷ n. You sum the x, y, xy and x² values across your points and plug them in. The calculator does it for any list of x,y pairs and gives the equation and r².

What is r² in regression?

R² (the coefficient of determination) measures how well the line fits — it is the share of the variation in y explained by x, from 0 (no fit) to 1 (perfect fit). An r² of 0.9 means 90% of the variation is explained by the line. The calculator reports it alongside the equation.

What does the slope and intercept mean?

The slope (m) is how much y changes for each one-unit increase in x; the intercept (b) is the predicted y when x is 0. Together they define the best-fit line you can use to predict y from a new x value.

Related tools