﻿1
00:00:00,100 --> 00:00:01,466
So polynomial features.

2
00:00:01,466 --> 00:00:04,666
And then of course,
well you know anytime we import a class

3
00:00:04,666 --> 00:00:07,800
the next step is to
of course create an object of this class.

4
00:00:07,900 --> 00:00:12,300
And this object will be exactly the tool
that will allow us to create this matrix

5
00:00:12,300 --> 00:00:15,366
of the features x1, x1 squared x1.

6
00:00:15,366 --> 00:00:17,900
At the power of n,
I will precise what n we choose.

7
00:00:17,900 --> 00:00:19,500
Then we will choose several of them.

8
00:00:19,500 --> 00:00:20,166
But there you go.

9
00:00:20,166 --> 00:00:23,266
That's what we build
with this polynomial features class.

10
00:00:23,633 --> 00:00:27,333
And so well we're going to call this
object of this class poly

11
00:00:28,033 --> 00:00:30,866
underscore rig as polynomial regressor.

12
00:00:30,866 --> 00:00:33,933
But it's not exactly the regressor itself
because you know,

13
00:00:34,066 --> 00:00:37,000
the final polynomial regressor
will be the combination

14
00:00:37,000 --> 00:00:40,633
of this matrix of powered features
and the linear regressor.

15
00:00:40,633 --> 00:00:43,433
And that's why we will call it actually
Lin rank two.

16
00:00:43,433 --> 00:00:44,366
You will see.

17
00:00:44,366 --> 00:00:47,833
So poly
rag will be created as an instance or

18
00:00:47,833 --> 00:00:50,833
an object of this polynomial features
class.

19
00:00:51,000 --> 00:00:54,000
So we're going to paste that here
adding some parenthesis.

20
00:00:54,300 --> 00:00:56,833
And that is where
we're going to choose the n.

21
00:00:56,833 --> 00:00:57,500
You know that.

22
00:00:57,500 --> 00:01:00,600
And here is exactly chosen
in this new class.

23
00:01:00,900 --> 00:01:03,333
So first we're going to start with two
okay.

24
00:01:03,333 --> 00:01:06,333
We're going to 
build a polynomial regression model

25
00:01:06,500 --> 00:01:10,433
resulting from the equation
y equals b0 plus b1 x1

26
00:01:10,433 --> 00:01:15,500
plus b2 x1 squared where x1 is of course
the position levels and y is the salaries.

27
00:01:15,900 --> 00:01:16,200
All right.

28
00:01:16,200 --> 00:01:17,333
So let's create this.

29
00:01:17,333 --> 00:01:22,933
Let's precise degree which is the name
of the parameter for that n equals two.

30
00:01:23,166 --> 00:01:25,733
And then we'll try it three and four okay.

31
00:01:25,733 --> 00:01:27,633
Then next step.

32
00:01:27,633 --> 00:01:31,733
Well the next step is now to proceed
to this transformation

33
00:01:32,033 --> 00:01:34,933
of this simple matrix of features
containing

34
00:01:34,933 --> 00:01:40,533
only x1,
meaning exactly this columns so far

35
00:01:40,533 --> 00:01:43,533
this is our matrix of features
of only one feature.

36
00:01:43,700 --> 00:01:46,766
And now we're going to transform
this matrix of a single feature

37
00:01:47,000 --> 00:01:50,900
into this new matrix of features
containing x1

38
00:01:50,900 --> 00:01:54,000
as a first feature,
x1 squared as a second feature.

39
00:01:54,133 --> 00:01:57,133
And then that's it,
because so far we start with an equal to.

40
00:01:57,300 --> 00:01:59,200
But if we chose for example n
equal three, well,

41
00:01:59,200 --> 00:02:03,033
the matrix of features would be x1,
x1, squared and x1 and the power of three.

42
00:02:03,200 --> 00:02:03,900
All right.

43
00:02:03,900 --> 00:02:05,400
So that's what we're going to do.

44
00:02:05,400 --> 00:02:10,266
And to do this well we're going to take
of course our fully read object again

45
00:02:10,566 --> 00:02:14,933
from which we're going to call the method
fit transform.

46
00:02:14,933 --> 00:02:17,933
Again you're starting to know this method

47
00:02:18,000 --> 00:02:21,466
that's you know, the method
that usually proceed to a transformation.

48
00:02:21,466 --> 00:02:26,033
And here the transformation
is to turn this matrix of a single feature

49
00:02:26,033 --> 00:02:29,800
into this new matrix of features
composed of x1 as the first feature,

50
00:02:29,800 --> 00:02:31,733
and x1 squared is the second feature.

51
00:02:31,733 --> 00:02:34,800
All right, fit transform,
then some parenthesis.

52
00:02:35,266 --> 00:02:38,100
And then according to you now
what do we have to input here?

53
00:02:38,100 --> 00:02:39,633
Well, that's pretty obvious.

54
00:02:39,633 --> 00:02:43,100
That's exactly the matrix of features
we want to transform

55
00:02:43,100 --> 00:02:46,633
into this matrix of squared features
let's say right.

56
00:02:46,966 --> 00:02:50,466
So x x of course
that's what we want to transform x

57
00:02:50,466 --> 00:02:53,766
so far is only composed of this column
okay.

58
00:02:53,766 --> 00:02:54,933
So fit transform x.

59
00:02:54,933 --> 00:02:57,066
And now we have
our new matrix of features.

60
00:02:57,066 --> 00:03:01,166
However this exactly returns
this new matrix of features.

61
00:03:01,200 --> 00:03:03,133
And now we're going to
create a new variable

62
00:03:03,133 --> 00:03:05,700
which will be this new matrix of features
itself.

63
00:03:05,700 --> 00:03:08,400
And we're going to call it x underscore.

64
00:03:08,400 --> 00:03:11,733
Poly equals what is returned by this

65
00:03:11,900 --> 00:03:15,400
fit transform method applied to x. Great.

66
00:03:15,400 --> 00:03:19,533
So now we have exactly the matrix
of features composed of the position

67
00:03:19,533 --> 00:03:22,533
levels
and the squares of the position levels.

68
00:03:22,733 --> 00:03:23,466
Good.

69
00:03:23,466 --> 00:03:25,766
So now according to you
what are we going to do.

70
00:03:25,766 --> 00:03:29,400
Well as I said at the beginning,
it's like now we have a new matrix

71
00:03:29,400 --> 00:03:32,400
of features, you know,
composed of these two variables here.

72
00:03:32,733 --> 00:03:36,000
And well, very simply,
we just have to build a linear regression

73
00:03:36,000 --> 00:03:39,800
model that will integrate these features
into this equation.

74
00:03:39,800 --> 00:03:43,566
Y equals b0 plus b1 x1 plus b2 x1 squared.

75
00:03:43,633 --> 00:03:44,033
Right.

76
00:03:44,033 --> 00:03:46,800
You see the idea
that's where the linear comes from.

77
00:03:46,800 --> 00:03:48,233
And therefore well you know what to do.

78
00:03:48,233 --> 00:03:50,666
You know how to create
such a linear regressor.

79
00:03:50,666 --> 00:03:52,866
But we have to create a new one
which is of course

80
00:03:52,866 --> 00:03:57,000
different than this one, because this one
is already trained on this matrix

81
00:03:57,000 --> 00:04:00,800
of single feature X and therefore
having already learned coefficient.

82
00:04:01,300 --> 00:04:06,600
So now we need to create a new one which
we're going to call, of course Lin rag.

83
00:04:06,933 --> 00:04:10,500
And I'm adding underscore two,
which therefore will be

84
00:04:10,500 --> 00:04:14,600
a new object of this linear regression
class.

85
00:04:14,600 --> 00:04:16,200
Adding some parenthesis.

86
00:04:16,200 --> 00:04:20,733
And well, this object will be now trained
on this new matrix of features

87
00:04:20,733 --> 00:04:23,600
composed of the position levels
at different powers.

88
00:04:23,600 --> 00:04:26,600
And of course then the salary,
because indeed we need the dependent

89
00:04:26,600 --> 00:04:30,533
variable vector to train the linear
regression model and any machinery model.

90
00:04:30,600 --> 00:04:31,333
All right.

91
00:04:31,333 --> 00:04:36,266
So the next step and final step is to
of course call this new linear

92
00:04:36,300 --> 00:04:39,800
regressor object
that we've just created from which

93
00:04:39,800 --> 00:04:43,733
we're going to call the fit method
which will take as input.

94
00:04:43,800 --> 00:04:47,766
Of course, this new matrix of features
containing the position labels

95
00:04:47,766 --> 00:04:51,533
at different powers, and of course
the same dependent variable vector

96
00:04:51,533 --> 00:04:54,200
which are the salaries.
All right. So let's do this.

97
00:04:54,200 --> 00:04:58,466
Let's input first x fully and then y.

98
00:04:58,466 --> 00:04:59,566
And there you go.

99
00:04:59,566 --> 00:05:02,100
You have your polynomial regression model.

100
00:05:02,100 --> 00:05:03,366
Congratulations.

101
00:05:03,366 --> 00:05:06,200
Now you know how to build
a nonlinear regression model.

102
00:05:06,200 --> 00:05:09,133
And that's what we're going to see
clearly with the next steps.

103
00:05:09,133 --> 00:05:11,633
When visualizing the linear
regression results first

104
00:05:11,633 --> 00:05:13,433
and the polynomial regression results.

105
00:05:13,433 --> 00:05:15,066
Now you know how to build such a model.

106
00:05:15,066 --> 00:05:17,000
And you have them in the toolkit.

107
00:05:17,000 --> 00:05:19,000
So are you getting more power in machine
learning?

108
00:05:19,000 --> 00:05:21,300
More knowledge, more skills?
Congratulations!

109
00:05:21,300 --> 00:05:22,166
That's amazing.

110
00:05:22,166 --> 00:05:26,466
And now I can't wait to move on
to the next tutorial to show you indeed

111
00:05:26,533 --> 00:05:30,666
the different results we get with linear
regression and polynomial regression.

112
00:05:31,000 --> 00:05:32,433
So I'll see you in the next tutorial.

113
00:05:32,433 --> 00:05:36,533
Let's quickly run this cell in order to,
you know, get the model itself.

114
00:05:36,666 --> 00:05:38,933
And now,
whenever you're ready, let's proceed

115
00:05:38,933 --> 00:05:41,333
to the next tutorial
for the visualizer sessions.

116
00:05:41,333 --> 00:05:43,200
And until then, enjoy machine learning.
