Hello and welcome back to the course on Machine Learning.
Today we're talking about the polynomial regression.
So let's get straight into it.
We already know a couple of types of regressions.
We know the simple linear regression which we can see over here.
Then we've also discussed
the multiple linear regression which is written out over here.
And finally we've got the polynomial linear regression which is written out
here.
So notice how it's very similar to the multiple linear regression.
But at the same time instead of the different variables
like x2, x3, x4 and so on zn
we have the same variable x1, but it is in a different power.
So instead of x2 we have x1 squared, instead of x3 would have x1 cubed.
And so instead of x n we would have x1 to the power of n.
So basically we're using one variable.
But we're using the different powers of that variable.
So let's have a look at
when you would use a polynomial regression when it would come in handy.
Let's say we've got a observation a set of observations which is then
the line that fits this data is obviously a simple linear regression.
As you can see, it feels fitted quite well.
But let's, for a change, say that the data set looked something like this.
So if we try to use a simple linear regression here
which is expressed like that.
You'll see that it doesn't fit quite well.
So in the middle you've got data underneath.
And then as you go further the data will be above the line.
So how can we correct that.
Well we can try to correct that by using a polynomial regression.
Let's have a look.
So instead of the linear regression we're going to conduct a polynomial regression.
And that in this case fits perfectly.
And what is a formula.
Well that is a formula for this particular case y equals b0.
So that's a constant plus b1 x1. So that's a simple linear regression part.
But then we're adding the b2 x1 squared.
And the b2 x1 squared gives its that parabolic effect so that the curve
becomes parabolic and therefore it will fit this data better.
As you can see,
polynomial regression is a bit different to a simple linear regression.
And at the same time it has its own use cases.
So it's all in comes on a case by case basis. You.
You have a problem.
And then you might try a simple linear regression or multiple linear regression
if you have many variables.
Or you might try a polynomial linear regression and see what happens.
And sometimes the polynomial regressions do work better.
For example, they're used to describe how diseases spread
or pandemics and epidemics are spread across territory or across population.
Polynomial linear regressions can be handy there.
And they also have other use cases.
So it's a matter of what works best.
So it's always good to have more tools in your arsenal.
And we have one final question left.
The question is why is it called linear still.
Right.
So we saw those different powers squared cube two to the power of n and so on.
Why is it still called linear. And I'll show you what I mean.
If you look on the left here it says polynomial linear regression.
So why is it still called a linear regression if it's a polynomial
regression?
Well, the trick here is that when we're talking about linear and non-linear,
we're not actually talking about the x variables.
Right.
So even though they're non linear here the relationship between y and x is.
When you're talking about the class of a regression you're talking.
So whether it's linear non-linear you're talking about the coefficients here.
So that's the interesting part.
So whether or not this function which we have here.
So y is a function of x right.
And so the question is can this function be expressed as a linear
combination of these coefficients that because ultimately they are the unknowns.
Right.
So your goal when you're building a regression is to find these coefficients,
find out their actual values so that then further down the track
you can use those coefficients to then plug in x and predict y
whether it's a linear well it's a simple linear multiple linear
regression or polynomial linear regression.
That's your goal to find these B coefficients.
And that's why linear non linear refers to the coefficients.
So an example of a nonlinear regression
would be if the equation was y equals b0 plus b1 x1
divided by b2 plus x2 or something,
or a b0 divided by b1 plus x1.
So a situation where you really cannot replace the coefficients
with other coefficients to turn the equation into a linear one
in regards to the coefficients, not the x values.
So there you go.
That's why a polynomial regression is still called a linear regression.
And that's your fun fact for the day.
And maybe you can show off to your colleagues.
And also because of that, the polynomial linear regression
is actually a special case of the multiple linear regression.
So that's just something to also kind of note that
this is a version of the multiple linear regression.
Rather than a standalone absolutely new type of regression.
So I hope you enjoyed today's tutorial and I look forward to seeing you next time.
Until then, enjoy machine learning.