Linear Regression Calculator: Decode Best Fit Free in 3 Steps

Linear Regression Calculator y = a + bx

Fit a line of best fit by least squares: slope, intercept, R² and predictions.

Regression equation
Slope (b)
Intercept (a)
r
Show working (LaTeX)

This free linear regression calculator fits the line of best fit to your data by least squares, returning the slope, intercept, correlation, R² and predictions.

How to use the linear regression calculator

Enter your X and Y values into the linear regression calculator above and press Fit line. It computes the least squares regression equation, the slope and intercept, the correlation r and R², and will predict y for any x you give it. As a line of best fit calculator and least squares calculator, it does the algebra for you.

linear regression calculator scatter plot with a line of best fit through the points
Least squares finds the line that minimizes the total squared vertical distance to the points.

What is linear regression?

Linear regression models the relationship between two variables as a straight line. See the simple linear regression reference for the derivation.

Definition. Simple linear regression fits $y=a+bx$ by minimizing the sum of squared residuals between the line and the data.

Regression formula

$$b=\frac{\sum (x_i-\bar{x})(y_i-\bar{y})}{\sum (x_i-\bar{x})^2}\qquad a=\bar{y}-b\bar{x}$$

How to find the line of best fit step by step

  1. Find the means of x and y.
  2. Compute the slope b from the formula above.
  3. Get the intercept a, then read R² to judge the fit.
✅ TipR² ranges from 0 to 1: it is the share of the variation in y explained by x. Closer to 1 means a tighter fit.

Worked example

For X = 1,2,3,4,5 and Y = 2,4,5,4,6, the least squares line is about $y=1.8+0.8x$, with R² ≈ 0.73.

Why linear regression matters in machine learning

Linear regression is the first model in machine learning for beginners — the foundation of supervised learning. It relies on the standard deviation and on minimizing a loss with the derivative.

🤖 ML insight

Training linear regression means minimizing the mean squared error — exactly what gradient descent does by following the derivative of the loss downhill.

Frequently asked questions

What does this linear regression calculator output?
The regression equation, slope, intercept, correlation r, R² and an optional prediction.
How many data points do I need?
At least two pairs, and X and Y must have the same count.
What does R² mean?
The proportion of variation in y explained by x, from 0 (none) to 1 (perfect).
What is least squares?
The method that picks the line minimizing the total squared vertical distance to the points.
Is the linear regression calculator free?
Yes, completely free and browser-based.

Reading the results

The slope tells you how much y changes for a one-unit rise in x, and the intercept is the predicted y when x is zero. A positive slope means the variables move together; a negative slope means they move apart. The correlation r shares the slope’s sign and ranges from −1 to 1.

Always plot your data before trusting a line. The method assumes a roughly straight relationship, a similar spread of points along the line, and no extreme outliers. If the cloud of points curves or fans out, a straight line will mislead — consider a transformation or a non-linear model instead.

Linear regression calculator: summary

This linear regression calculator gives the line of best fit and its quality in one click. Pair it with the standard deviation calculator and keep learning with machine learning for beginners.

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top