Source: https://goodhandover.co.uk/tools/least-squares-regression-calculator/

[Computer science maths](https://goodhandover.co.uk/tools/computer-science-maths/#year-2) / Year 2

🔒 Files never leave your device

# Least squares regression calculator

Fit a line to paired values and inspect residuals and R². Your inputs stay on your device.

## Set up your task

Ready. Processing stays in this browser.

Files and text stay on your device. [Privacy details](https://goodhandover.co.uk/privacy/).

 

## How to use Least squares regression calculator

Fit a line to paired values and inspect residuals and R². The pre-filled problem gives you a worked starting point. Compare the response with your own working before trying the self-check below.

 

- Check the example inputs: x values, y values.

- Change the inputs for your problem. Results update as you type, so finish entering the values before copying an answer.

- Use the working to check an intermediate value or assumption. Then change the example as suggested in the self-check and compare the result.

 

## Supported inputs and limits

Enter two lists of up to 64 real numbers in matching observation order. Use at least two distinct x values.

 

## How it works

A least-squares line estimates a response y from a predictor x. It minimises the sum of squared vertical gaps between the observations and the fitted line. The slope describes the fitted change in y per unit x. The intercept is the estimate when x equals zero.

Residuals expose where the model is under or over the observed values. The fitted line passes through the paired means when the model includes an intercept. R² compares residual variation with variation around the response mean. A tidy fit can still hide patterns in residuals or depend heavily on a single outlier.

 

## Example

Run the pre-filled example. Its first result is “Slope: 2 · Intercept: 1”.

x values

1 2 3

y values

3 5 7

Slope: 2 · Intercept: 1
Sum of squared residuals: 0
R²: 1
Residuals: 0, 0, 0

 

## Questions about Least squares regression calculator

### Can the line be used to predict far beyond the input range?

A fitted line can be evaluated there, but the observed data do not show whether the relationship continues outside their range.

### Why must x vary?

The slope formula divides by the sum of squared x deviations from their mean. A constant x column makes that denominator zero.

### Keep x unchanged and make all three y values equal to 4.

The fitted line has slope zero and intercept four. R² is undefined because there is no response variation to explain.

 
 

## Related tools

[Year 2: Algorithms and theory](https://goodhandover.co.uk/tools/computer-science-maths/#year-2)

- [Matrix inverse calculator](https://goodhandover.co.uk/tools/matrix-inverse-calculator/)

- [Breadth-first search calculator](https://goodhandover.co.uk/tools/breadth-first-search-calculator/)

- [Matrix determinant calculator](https://goodhandover.co.uk/tools/matrix-determinant-calculator/)

- [Topological sort calculator](https://goodhandover.co.uk/tools/topological-sort-calculator/)

 

Last updated 24 November 2026
