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.
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
- Enter your x values, separated by commas.
- Enter the matching y values, in the same order.
- Read the best-fit line in the form y equals m x plus b.
- See the slope and intercept, and how well the line fits.
Here is what each result means:
| Result | What it means |
|---|---|
| Best-fit line | The line that minimizes squared distance to the points. |
| Slope | How much y changes for each unit of x. |
| Y-intercept | The 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.
- Find the mean of the x values and of the y values.
- Use the deviations from those means to compute the slope.
- 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.
| Value | What it tells you |
|---|---|
| Positive slope | y rises as x rises |
| Negative slope | y falls as x rises |
| Slope near zero | Little linear relationship |
| Intercept | The 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.
| Quantity | What it measures |
|---|---|
| Slope and intercept | The trend line itself |
| R squared | The 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
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
- Linear regression (Wikipedia).
- Least squares regression (Maths Is Fun).
- Coefficient of determination (Wikipedia).
Related Calculators
Looking for more statistics tools?
Explore all math calculatorsThis 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 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.




