Ordinary least squares.
So we have our data points.
Now the question is that we're answering in this tutorial is
how do we know which of the sloped lines is the best one?
Is it this one? Is it this one? Is it this one?
Is it this one or is it this one?
As we can see, there can be multiple slope lines
that we can draw through our data points.
And how do we know which one is the best one.
Which is the best linear regression.
And in fact how do we even define the best one.
So in order to answer those questions, we need to look at a method
called the ordinary least squares method.
And the way it works in a visual sense is we need to take our data points
and project them vertically onto,
our linear regression line.
Now we would need to do this for every single linear regression line
that we're considering.
But for simplicity's sake, in
this tutorial we're just going to do it with this, line here in the middle.
Now for each pair of points we have two values y I and y I hat.
So what are these values?
Y is the actual, amount
of, potatoes in our case, in our example, potatoes yielded from the farm
when that, specific amount of nitrogen fertilizer was used.
So let's say 15kg of nitrogen fertilizer were used
and the farm yielded two tons of potatoes.
Y I hat, on the other hand, is what this linear regression
that we're considering what it predicts the yield,
to be or two would have been.
So in this case, let's say I again, 15kg of nitrogen were used.
But the, linear regression that we're looking at predicts that only
one and a half tonnes of potatoes, would have been yielded from the farm.
As you can see, there's a slight difference between the,
actual value, actual yield and the predicted.
And that's normal.
It's never going to be perfectly.
This line's never going to go perfectly through every single data point.
That's simply impossible.
but what we want to do is we want to find the best line,
and it will be related to how small
these differences are, as we can imagine.
So let's have a look here.
There's our y and y hat.
The difference between them is called the residual.
here's our equation.
And the best equation is such equation A where b or where
such an equation where the parameters b0 and b1 are such
that the sum of the squares of the residuals
is minimized, and that's why it's called the ordinary least squares method.
So we need to take all of these, residuals, these differences.
We need to square them for every single data point.
and then we need to add up the sum and whenever we find the smallest value.
So for whichever regression line, this value is going to be the smallest,
that will be the best regression line.
And that will guarantee that the line is going nicely through our data points.
And it is the best line or the best linear
regression to use for modeling our problem.
So there you go.
That's in a nutshell how the ordinary least squares method works.
And I look forward to seeing you next time.
And till then enjoy machine learning.