Skip to main content
Skip to calculator
Advertisement

Last updated: August 1, 2026

Least Squares Regression Calculator

Quick Answer

This least squares regression calculator parses paired x and y data, computes the best-fit line, reports slope, intercept, correlation, R², and predicts a y-value for a chosen x input.

Least squares regression finds the best-fit line by minimizing squared errors, then uses that line to estimate y for any chosen x-value.

Helpful
Not helpful
Save as image
Share
Embed
Cite
Write feedback

Formula

slope = (nΣxy - ΣxΣy) / (nΣx² - (Σx)²), intercept = (Σy - slope·Σx) / n, predictionY = slope·predictX + intercept

Where:

  • n=Number of data pairs
  • x=Independent variable values
  • y=Dependent variable values
  • m=Slope of the regression line
  • b=Y-intercept of the regression line
  • \hat{y}=Predicted y-value
Least Squares Regression IllustrationPoints scattered near a straight line with slope, intercept, and prediction labels.Least Squares RegressionFit a best-fit line and forecast new y-valuesCore Formulaŷ = mx + bUse slope and intercept to predict y
Least squares regression places the line where total squared residual error is smallest, then uses that line for prediction.

Worked Examples

Perfect positive trend

Fit points (1,2), (2,4), and (3,6), then predict y at x = 4.

  1. 1Compute the slope from the paired sums.
  2. 2The numerator and denominator produce m = 2.
  3. 3Solve for the intercept: b = 0.
  4. 4Predict at x = 4: y = 2(4) + 0 = 8.
Final Answer: y = 2x, predicted y = 8

Line with intercept

Use points following y = x + 1.

  1. 1The data increases by 1 in y for every 1 in x.
  2. 2Least squares returns slope m = 1.
  3. 3The intercept is b = 1.
  4. 4Prediction at x = 5 is 6.
Final Answer: y = x + 1, predicted y = 6

Negative slope

Fit a downward trend to see a negative relationship.

  1. 1The points drop by 2 in y when x rises by 1.
  2. 2Least squares returns m = -2.
  3. 3The intercept is b = 7.
  4. 4Prediction at x = 4 gives y = -1.
Final Answer: y = -2x + 7, predicted y = -1

Near-linear decimal data

Model decimal observations and inspect fit quality.

  1. 1Compute the regression line from all four pairs.
  2. 2The slope is about 0.93 and intercept about 0.2.
  3. 3R² stays close to 0.98, so the fit is strong.
  4. 4Prediction at x = 5 is about 4.85.
Final Answer: Approximately y = 0.93x + 0.2, predicted y ≈ 4.85

Introduction

Least squares regression finds the straight line that minimizes squared vertical errors between actual data points and the fitted line. It is a standard tool for spotting linear trends, making forecasts, and summarizing how strongly two variables move together.

What Least Squares Regression Does

The calculator turns paired x and y observations into a best-fit line in the form y = mx + b.

  • Uses all pairs at once

  • Minimizes squared residuals

  • Reports slope and intercept

  • Supports quick prediction at a new x-value

What You Need to Enter

You need two equal-length lists of numeric values plus an x-value for prediction.

  • At least two pairs are required

  • x and y lists must align position-by-position

  • Comma, space, and line-break separators work

  • PredictX must be a finite number

Formula Breakdown

The slope uses covariance scaled by x-variance, and the intercept adjusts the line to pass through the mean point.

  • Slope captures average change in y per unit x

  • Intercept shows where the line crosses the y-axis

  • Prediction uses slope-intercept form

  • R² summarizes explained variation

Understanding Correlation and R²

Pearson r shows direction and strength of a linear relationship, while R² shows how much variation the line explains.

  • r near 1 means strong positive linear trend

  • r near -1 means strong negative linear trend

  • r near 0 means weak linear relationship

  • R² ranges from 0 to 1

How to Use the Tool

Enter the two data lists, choose a prediction x-value, and read the line, fit strength, and forecast.

  • Paste x-values

  • Paste matching y-values

  • Enter the x-value to predict

  • Review equation, coefficients, and fit metrics

Best Practices

Regression only helps when a straight-line relationship is reasonable and data quality is consistent.

  • Check for obvious outliers

  • Use consistent measurement units

  • Avoid repeating the same x-value for every point

  • Treat predictions outside the data range carefully

Common Errors to Avoid

Most mistakes come from mismatched list lengths, non-numeric input, or trying to fit vertical-line data.

  • Do not mix text labels with numbers

  • Keep list counts equal

  • Use at least two pairs

  • Do not enter identical x-values only

FAQs

How many data points do I need?

At least two paired observations are required, but more points usually create a more reliable fit.

What if my x-values and y-values do not match in count?

The calculator rejects the input because each x-value must pair with exactly one y-value.

Can this handle decimals and negative values?

Yes. Both lists can include positive, negative, and decimal values as long as they are finite numbers.

What does the slope mean?

The slope tells you how much the predicted y-value changes for each 1-unit increase in x.

What does R² tell me?

R² shows the fraction of y-variation explained by the fitted line, with 1 meaning a perfect linear fit.

Why is the correlation coefficient zero for some flat data?

If all y-values are identical, there is no variation to measure linear correlation, so the calculator returns 0 for r and R².

Can I predict beyond my input range?

Yes, but extrapolated predictions are less reliable because they extend the line beyond observed data.