Course Content

Linear Regression with Python

We now know that Linear Regression is just a line that best fits data. But how can you tell which is the right one?

Well, you can calculate the difference between the predicted value and the actual target value for each data point in the training set.

These differences are called **residuals**(or **errors**). And the goal is to make the residuals as small as possible.

## Ordinary Least Squares

The default approach is the **Ordinary Least Squares**(**OLS**) method: take each residual, square it(mainly to get rid of the sign of a residual), and sum all of them. That is called **SSR**(**Sum of squared residuals**). And the task is to find the parameters that minimize the SSR.

## Normal Equation

Fortunately, we do not need to try all the lines and calculate SSR for them. The task of minimizing SSR has a mathematical solution that is not very computationally expensive.

This solution is called the **Normal Equation**.

This equation gives us the parameters of a line with the least SSR.

Did you not understand how it works? No worries! It is pretty complex maths. But you don't have to calculate the parameters with your hands. Many libraries have already implemented linear regression.

So hop into the following chapters. They will show you how to build the linear regression model using those libraries.

## Quiz

Consider the image above. Which regression line is better?

Select the correct answer

y_true - y_predicted is called

## Select a few correct answers

What is the mathematical solution to finding parameters with the least SSR?

Select the correct answer

Section 1.

Chapter 2