331+ free tools. No sign-up. No hidden fees. Explore the toolkit

Linear Regression Calculator

Linear regression finds the straight line that best fits your data — the line that gets as close as possible to all your points at once. Once you have the line, you can predict Y for any X, see how strongly the two variables are related, and say how much of the variation in Y the line actually explains. It is the workhorse of data analysis, from forecasting sales to calibrating instruments.

Paste two lists of paired values and this calculator fits the least-squares line, giving the slope, intercept, equation, correlation, r², and a prediction for any x you enter — plus the predicted value for every x in your list.

Separate numbers with commas, spaces or new lines. The first X value pairs with the first Y value, and so on.

Same number of values as the X list — each Y value pairs with the X value in the same position.

Enter an x value and the calculator predicts y from the fitted line. Predictions beyond your data's range (extrapolation) are less reliable.

Regression equation (least squares)

Save to Pinterest
Note: the fitted line is only as good as the straight-line assumption. If your data curves, the line will miss it systematically — always check the predicted values against your actual Y values. Predictions beyond the range of your X data (extrapolation) assume the trend continues, which it may not. If every X value is the same, the slope is undefined and the calculator says so.

How It Works

The line has the form ŷ = a + b·x, where b is the slope and a is the intercept (the predicted Y when X = 0). The least-squares method picks the a and b that minimise the sum of the squared vertical distances between the points and the line — the total squared error. Squaring the distances means large misses count far more than small ones, so the line is pulled towards the bulk of the points. The fitted line is a linear equation in x, of the form y = a + bx.

The formulas use the means of X and Y (x̄ and ŷ) and the sums of squared and cross deviations:

b = Σ(x − x̄)(y − ŷ) / Σ(x − x̄)²    and    a = ŷ − b·x̄

The line always passes through the point (x̄, ŷ) — the centre of the data. The correlation r measures how tightly the points hug the line, from −1 (perfect falling line) to +1 (perfect rising line), and r² is the share of the variation in Y that the line explains: r² = 0.60 means 60% explained and 40% left over as scatter around the line.

To predict, put any x into the equation: ŷ = a + b·x. Predictions inside the range of your data (interpolation) are the most trustworthy; predictions outside it (extrapolation) assume the straight-line trend keeps going, which is a real assumption, not a fact.

Worked Example

Take X = 1, 2, 3, 4, 5 and Y = 2, 4, 5, 4, 5. The means are x̄ = 3 and ŷ = 4. The cross-deviation sum is (1−3)×(2−4) + (2−3)×(4−4) + (3−3)×(5−4) + (4−3)×(4−4) + (5−3)×(5−4) = 4 + 0 + 0 + 0 + 2 = 6, and the sum of squared X deviations is 4 + 1 + 0 + 1 + 4 = 10. So the slope is b = 6 / 10 = 0.6, and the intercept is a = 4 − 0.6 × 3 = 2.2. The equation is ŷ = 0.6x + 2.2, with r = 0.7746 and r² = 0.6.

Predicting at x = 6 gives ŷ = 0.6 × 6 + 2.2 = 5.8. The predicted values for the entered X list are 2.8, 3.4, 4.0, 4.6 and 5.2 — compare them with the actual Y values (2, 4, 5, 4, 5) to see how much scatter the line leaves unexplained.

Assumptions

Sources: No external data is used on this page — every figure is calculated from the values you enter, using the standard least-squares formulas for slope and intercept. Last reviewed: 15 November 2026.

Built and tested by SumKitTool — see how we check our numbers.

How to Use This Calculator

Paste your X values in the first box and your Y values in the second, separated by commas, spaces or new lines, then enter the x value you want a prediction for. The result updates as you type: the headline is the regression equation, and the table shows the slope, intercept, r, r², the prediction, the predicted values for your X list, and the means. Reset restores the worked example.

Try the worked example: the defaults give ŷ = 0.6x + 2.2, with a prediction of 5.8 at x = 6. Change the Y list to "2, 4, 6, 8, 10" and the line becomes ŷ = 2x exactly, with r = 1 and r² = 1 — a perfect fit. Try making all the X values the same, and the calculator reports that the slope is undefined.

Tips and Practical Advice

Read r² before you trust a prediction. An r² of 0.6 means 40% of the variation is unexplained scatter — your predictions will be roughly right on average, but individual predictions can be well off. An r² near 1 means the line is doing nearly all the work.

Outliers pull a regression line hard, because least squares squares the errors. A single extreme point can tilt the whole line. If one point sits far from the rest, try the calculation with and without it and see how much the slope changes.

Never extrapolate far beyond your data without saying so. A line fitted to house prices from 2010–2020 will happily predict a price for 2040 — but markets, policies and economies change, and the line knows nothing about any of that.

Frequently Asked Questions

What is linear regression?

Linear regression finds the straight line that best fits a set of paired data points, using the least-squares method — the line that minimises the sum of the squared vertical distances from the points to the line. The result is an equation, ŷ = a + bx, that you can use to predict Y for any X. For X = 1, 2, 3, 4, 5 and Y = 2, 4, 5, 4, 5, the line is ŷ = 0.6x + 2.2.

What do the slope and intercept mean?

The slope is how much Y changes for each 1-unit increase in X: a slope of 0.6 means Y rises by 0.6 for every extra unit of X. The intercept is the predicted Y when X = 0 — here 2.2. Together they define the line: predicted Y = intercept + slope × X.

What does r² tell me about the fit?

r² is the share of the variation in Y that the line explains, from 0 (the line explains nothing) to 1 (a perfect fit). An r² of 0.6 means 60% of the variation in Y is explained by the line and 40% remains as scatter around it. It is the single best number for judging whether your line is worth trusting.

Can I predict Y for an x outside my data?

You can, but the further outside your data's range you go, the less reliable the prediction. The line assumes the straight trend continues, which is often wrong — trends bend, saturate and reverse. Predictions inside your data's range are interpolation and are usually safe; predictions outside it are extrapolation and should always come with a warning.

Last updated: