Linear Regression Calculator

Quick answer

A linear regression calculator fits the best straight line through your data points, in the form y equals m x plus b. Enter your x and y values and it returns the slope, the intercept, and how well the line fits. It is the line that minimizes the squared distance to every point.

Updated 2026-09-09By Shakeel MuzaffarReviewed by Prof. Dr. Khalil Mudassar, PhD
Try
Statistics
The independent values, separated by commas.
The dependent values, in the same order and count as x.
Best-fit line
--
Slope (m)--
Y-intercept (b)--

Calculations run in your browser. Inputs are not sent to our servers; anything you Save stays in this browser only.

Saved results (0)

How to Use the Linear Regression Calculator

  1. Enter your x values, separated by commas.
  2. Enter the matching y values, in the same order.
  3. Read the best-fit line in the form y equals m x plus b.
  4. See the slope and intercept, and how well the line fits.

Here is what each result means:

ResultWhat it means
Best-fit lineThe line that minimizes squared distance to the points.
SlopeHow much y changes for each unit of x.
Y-interceptThe value of y when x is zero.

What Is Linear Regression?

Linear regression finds the straight line that best fits a set of paired data points. The line is written as y equals m x plus b, where m is the slope and b the intercept. It is chosen by least squares, which means it makes the total of the squared vertical distances from the points to the line as small as possible.

That line lets you describe a trend and make predictions. Once you have the slope and intercept, you can estimate y for a new x, and the goodness of fit, r squared, tells you how much of the pattern the line captures. Regression is one of the most-used tools in statistics, science and business.

How Does the Regression Calculator Work?

It uses the least-squares formulas to find the slope and intercept from your data.

Slope: m = sum((x - mean_x)(y - mean_y)) / sum((x - mean_x)^2) and b = mean_y - m x mean_x
  1. Find the mean of the x values and of the y values.
  2. Use the deviations from those means to compute the slope.
  3. Get the intercept so the line passes through the point of means.

The slope here is the same idea as the slope between two points; the slope calculator handles that simpler case.

Linear Regression Example

Fit a line to the points (1, 2), (2, 4), (3, 5), (4, 4), (5, 6).

Calculation: the mean of x is 3 and of y is 4.2. Working through the least-squares formulas gives a slope of about 0.8 and an intercept of about 1.8, so the best-fit line is roughly y = 0.8x + 1.8. The r squared is about 0.73, a good fit.

Reading the Slope and Intercept

The two numbers describe the trend in plain terms.

ValueWhat it tells you
Positive slopey rises as x rises
Negative slopey falls as x rises
Slope near zeroLittle linear relationship
InterceptThe predicted y when x is zero

The intercept is only meaningful when an x of zero makes sense for your data; otherwise treat it as a fitting constant.

Goodness of Fit vs the Line Itself

The line and how well it fits are two different things.

QuantityWhat it measures
Slope and interceptThe trend line itself
R squaredThe share of variation the line explains

A line always exists, but a low r squared warns that the points scatter far from it, so predictions will be rough.

What Affects the Best-Fit Line

The Spread of the Points

Tightly clustered points give a strong, reliable line; scattered points give a weak one.

Outliers

A single far-off point can pull the line toward it, changing the slope and intercept.

The Range of X

A wide range of x values gives a more stable slope than a narrow one.

When to Use a Linear Regression Calculator

Finding a Trend

Summarize how one variable moves with another as a single line.

Making Predictions

Estimate y for a new x from the fitted line.

Checking a Relationship

See from r squared whether a straight line is a reasonable model.

Common Mistakes

1. Fitting a Line to a Curve

If the data bends, a straight line misleads. Check a scatter plot first.

2. Ignoring Outliers

A single stray point can distort the line. Investigate before trusting the fit.

3. Predicting Far Outside the Data

The line is reliable only over the range you measured, not far beyond it.

4. Confusing Correlation with Cause

A strong fit shows association, not that x causes y.

5. Mismatched X and Y Counts

Each x needs a matching y. Unequal lists cannot be paired.

Accuracy and Limitations

The least-squares formulas are exact; only the displayed decimals are rounded.

What it calculates accurately

  • The best-fit slope and intercept
  • The line equation
  • The r-squared goodness of fit

What it does not do

  • Fit curves or multiple predictors
  • Detect the right model for you
  • Give confidence intervals
  • Draw the scatter plot

How We Fit Your Line

Method
Least squares: the slope from deviations about the means, then the intercept through the point of means.
Inputs used
Paired lists of x and y values.
Assumptions
A roughly linear relationship; at least two points; not all x equal.
Rounding
Slope, intercept and r-squared to four decimals.
Edge cases
Identical x values cannot be fit; a flat y gives a zero slope.
Sources
See Sources below.
Last reviewed
2026-09-08.

Frequently Asked Questions

What is linear regression?

It is a method that fits the best straight line through paired data. The line, written y equals m x plus b, minimizes the total squared distance from the points, and it summarizes the trend between two variables.

How do you find the regression line?

Find the mean of x and y, then use the deviations from those means to compute the slope, and place the intercept so the line passes through the point of means. This tool does the full calculation.

What does r squared mean?

R squared is the share of the variation in y that the line explains, from 0 to 1. An r squared of 0.8 means the line accounts for 80 percent of the pattern; the rest is scatter.

What is the difference between the slope and r squared?

The slope is the trend, how much y changes per unit of x. R squared is how well the line fits. A steep slope can still have a low r squared if the points scatter widely.

Can I use regression to make predictions?

Yes, within the range of your data. Plug a new x into the fitted line to estimate y. Predicting far outside the measured range is unreliable.

Does a good fit mean x causes y?

No. A strong fit shows the two variables move together, but correlation is not causation. Other factors, or chance, can explain the pattern.

How many points do I need?

At least two to define a line, but more points give a more reliable fit. A handful of well-spread points is far better than two.

What if my data is curved?

A straight line will fit poorly, shown by a low r squared. Curved data needs a different model, such as a polynomial or an exponential fit.

Is my information saved?

No. The calculation runs in your browser and nothing you enter is stored or sent anywhere, unless you choose Save, which keeps the result only on this device.

Sources

Related Calculators

Looking for more statistics tools?

Explore all math calculators

This calculator fits a straight line to paired data by the least-squares method. It assumes a roughly linear relationship; for curved or clustered data a straight line can mislead. Results are rounded for display. Spotted an error? Let us know.

Author

shakeel-Muzaffar
Founder & Editor-in-Chief at  ~ Web ~  More Posts

Shakeel Muzaffar is the Founder and Editor-in-Chief of MultiCalculators.com, bringing over 15 years of experience in digital publishing, product strategy, and online tool development. He leads the platform's editorial vision, ensuring every calculator meets strict standards for accuracy, usability, and real-world value. Shakeel personally oversees content quality, formula verification workflows, and the platform's commitment to publishing tools that are genuinely useful for students, professionals, and everyday users worldwide.