# Least Squares Calculator

The Least Squares calculator that helps to find the line of best fit of the form

## What Is Least Squares Calculator?

The Least Squares method is a statistical regression analysis method used to find the line of best fit of the form '**y = mx + b'** for a given set of data. Cuemath's 'Least Squares calculator' is a free online tool that finds the line of best fit for a given data set within a few seconds.

## How to Use the Least Squares Calculator?

Follow the steps mentioned below to find the line of best fit.

**Step 1**- Enter the data points in the respective input box.**Step 2**- Click on "**Calculate**" to find the least square line for the given data.**Step 3**- Click on "**Reset**" to clear the fields and enter a new set of values.

## How to Calculate Least Squares?

The least-squares method is used to find a linear line of the form y = mx + b. Here, 'y' and 'x' are variables, 'm' is the slope of the line and 'b' is the y-intercept.

Here, the value of slope 'm' is given by the formula, **m = (n ∑ (XY) - ∑ Y ∑ X) / (n ∑ (X ^{2}) - (∑ X)^{2})** and 'b' is calculated using the formula

**b = (∑ Y - m∑ X) / n**

Let us look at an example on how to find the least square line for a given data set.

**Solved Example :**

**Find the least square line for the data shown below.**

X | 1 | 2 | 3 | 4 | 5 |
---|---|---|---|---|---|

Y |
2 |
5 |
3 |
8 |
7 |

**Solution :**

X | Y | XY | X^{2} |
---|---|---|---|

1 | 2 | 2 | 1 |

2 | 5 | 10 | 4 |

3 | 3 | 9 | 9 |

4 | 8 | 32 | 16 |

5 | 7 | 35 | 25 |

∑ X = 15 | ∑ Y = 25 | ∑ XY = 88 | ∑ X^{2 }= 55 |

Find the value of m.

m = (n ∑ (XY) - ∑ Y ∑ X) / (n ∑ (X^{2}) - (∑ X)^{2})

= ( 5(88) - (15 × 25) ) / ( 5(55) - (15)^{2} )

= 13/10

= 1.3

Find the value of b.

b = (∑ Y - m∑ X) / n

= (25 - (1.3 × 15)) / 5

= 11/10

= 1.1

So, the required equation of least squares is y = (1.3)x + 1.1

Now, use our online Least Squares calculator and find the Least Squares Line for the given data points

X | 1.7 | 2.3 | 3.1 | 4.5 | 5.9 |
---|---|---|---|---|---|

Y |
12 |
45 |
29 |
65 |
45 |