regression line calculator

Linear Regression (Best-Fit Line)

Enter your x and y values as comma-, space-, or line-separated numbers. This calculator uses least squares regression to compute the best-fit line: y = mx + b.

Use the same number of x and y points.

What is a regression line calculator?

A regression line calculator helps you find the straight line that best describes the relationship between two variables. If your data pairs are written as (x, y), the calculator estimates the line:

y = mx + b

  • m is the slope (how much y changes when x increases by 1)
  • b is the intercept (the predicted y value when x = 0)

This is one of the most common tools in statistics, data science, engineering, and business analytics because it offers a fast way to model trends and make predictions.

How this linear regression calculator works

1) Least squares fitting

The calculator uses the least squares method, which picks the line that minimizes the sum of squared residuals (the squared vertical distances between observed points and predicted points on the line).

2) Correlation and goodness of fit

In addition to slope and intercept, it reports:

  • r (Pearson correlation): direction and strength of linear relationship
  • (coefficient of determination): fraction of variation in y explained by x
  • Standard error: typical prediction error around the fitted line

How to enter your data correctly

  • Put all x values in the X field and all y values in the Y field.
  • Keep the order matched: the first x pairs with the first y, second with second, etc.
  • Use equal lengths (same number of x and y values).
  • You can separate numbers with commas, spaces, or line breaks.

Example input:

X: 1, 2, 3, 4, 5
Y: 2.1, 4.0, 5.9, 8.2, 10.1

Interpreting your results

Slope (m)

If m = 2, then for each 1-unit increase in x, y increases by about 2 units on average. A negative slope means y decreases as x increases.

Intercept (b)

The intercept is the model's estimate when x = 0. It is mathematically important, but in some real-world contexts x = 0 may be outside your observed range, so interpret with care.

R and R²

Values of r near +1 or -1 indicate a strong linear relationship. Values near 0 indicate weak linear association. tells you how much variability in y is explained by the line. For example, R² = 0.84 means 84% of y variation is explained by x in this linear model.

Common mistakes to avoid

  • Mixing up x and y order.
  • Using mismatched list lengths.
  • Assuming high R² always means causation.
  • Applying linear regression to clearly non-linear patterns.
  • Ignoring outliers that can heavily influence the fitted line.

When to use this best-fit line tool

This calculator is ideal for:

  • Quick exploratory data analysis
  • Checking trends in small datasets
  • Creating simple predictive models
  • Homework or teaching linear regression concepts

For advanced work (multiple predictors, non-linear effects, confidence intervals, diagnostics), move to a full statistics package or programming workflow.

🔗 Related Calculators