﻿1
00:00:00,033 --> 00:00:01,033
Okay, great.

2
00:00:01,033 --> 00:00:02,700
And now,
the last thing that I'm going to do

3
00:00:02,700 --> 00:00:06,366
is maybe to take this code section
here. Cut.

4
00:00:07,266 --> 00:00:10,266
And I'm actually going to place it

5
00:00:10,333 --> 00:00:13,533
between the creation of the model
and the visualization,

6
00:00:13,533 --> 00:00:17,666
because I like to keep the best
for the end and for me, the best part,

7
00:00:17,666 --> 00:00:22,200
the most exciting part is the part
where we visualize our results.

8
00:00:22,200 --> 00:00:26,033
And for a second reason
is that we know that our problem is

9
00:00:26,033 --> 00:00:29,933
a nonlinear problem, and that therefore
we need a nonlinear regressor.

10
00:00:29,933 --> 00:00:32,066
And we're definitely already
convinced of that.

11
00:00:32,066 --> 00:00:35,366
That's why we don't need to execute
this code section before this one

12
00:00:35,533 --> 00:00:40,133
to convince ourselves that we need
indeed, a nonlinear regression model.

13
00:00:40,566 --> 00:00:42,466
So therefore, for the next regression

14
00:00:42,466 --> 00:00:46,133
models, we will make the prediction
before visualizing the results.

15
00:00:46,466 --> 00:00:48,900
And that's why I'm putting that here
first.

16
00:00:48,900 --> 00:00:51,300
Okay.
So I think the template is ready now.

17
00:00:51,300 --> 00:00:55,033
Well maybe we need to change
the polynomial here

18
00:00:55,033 --> 00:00:58,066
to generalize the template
as much as possible.

19
00:00:58,066 --> 00:01:00,066
So we'll replace polynomial here by.

20
00:01:00,066 --> 00:01:03,566
Well actually
let's just put predicting a new result.

21
00:01:03,733 --> 00:01:04,466
All right.

22
00:01:04,466 --> 00:01:08,200
And here we can replace polynomial
regression by regression

23
00:01:09,533 --> 00:01:10,566
model.

24
00:01:10,566 --> 00:01:11,233
All right.

25
00:01:11,233 --> 00:01:14,800
And now just to finish this template
for those of you who are also interested

26
00:01:14,800 --> 00:01:18,266
in getting a smoother curve
in your regression model, results.

27
00:01:18,333 --> 00:01:21,533
Well, there is this trick
we can do to increase the resolution.

28
00:01:21,833 --> 00:01:23,266
And we are going to do that right now.

29
00:01:23,266 --> 00:01:26,666
So it's just an optional code section
that I'm adding here in this template.

30
00:01:26,733 --> 00:01:30,600
I'm going to copy this because
we will have just a few things to change.

31
00:01:30,966 --> 00:01:33,966
And you know, for those of you
who really want a very smooth curve

32
00:01:34,200 --> 00:01:36,666
when you visualize the regression
model results,

33
00:01:36,666 --> 00:01:38,800
well, you can use the following code.

34
00:01:38,800 --> 00:01:43,500
So the trick is to actually create
a new sequence of levels.

35
00:01:43,500 --> 00:01:44,433
That means that hue.

36
00:01:44,433 --> 00:01:47,433
And we are predicting
only ten salaries of the ten levels.

37
00:01:47,466 --> 00:01:49,366
Well,
what we're going to do now in this section

38
00:01:49,366 --> 00:01:52,866
is that instead of predicting
only ten salaries of ten

39
00:01:52,866 --> 00:01:55,866
levels, we're going to predict
a lot more than ten levels.

40
00:01:56,100 --> 00:02:00,200
And to do that,
we will build a vector of imaginary levels

41
00:02:00,200 --> 00:02:04,833
that will actually be levels
from 1 to 10 incremented by 0.1.

42
00:02:05,033 --> 00:02:10,100
So that means I will consider
level one, level 1.1, 1.2, 1.3,

43
00:02:10,333 --> 00:02:14,666
up to 9.6, 9.7, 9.8 and 9.9.

44
00:02:15,000 --> 00:02:17,400
So that's what
we will create in the sequence.

45
00:02:17,400 --> 00:02:20,700
And therefore here,
instead of predicting only ten salaries,

46
00:02:20,900 --> 00:02:25,033
we will predict actually
90 salaries of 90 levels.

47
00:02:25,233 --> 00:02:26,233
So that's the trick.

48
00:02:26,233 --> 00:02:29,666
And to build this sequence
it's actually very simple.

49
00:02:29,666 --> 00:02:32,666
We are going to call this sequence x grid.

50
00:02:32,733 --> 00:02:38,133
You know because X grid will replace data
set dollar level here and data set here.

51
00:02:38,133 --> 00:02:41,133
And this x grid is going to be defined as

52
00:02:41,566 --> 00:02:44,566
SIC which is a function
that builds a sequence.

53
00:02:44,833 --> 00:02:48,200
And so in this function
we need to input three parameters.

54
00:02:48,433 --> 00:02:50,366
The lower bound of your sequence.

55
00:02:50,366 --> 00:02:54,100
That's actually mean data set level.

56
00:02:54,333 --> 00:02:55,300
Because by doing this

57
00:02:55,300 --> 00:02:58,933
we're taking the minimum of all the levels
in your original data set.

58
00:02:59,400 --> 00:03:03,966
All right then the next parameter
is the upper bound of your levels.

59
00:03:04,133 --> 00:03:05,400
That is level ten.

60
00:03:05,400 --> 00:03:08,300
And therefore we do the same
with the max here Max

61
00:03:08,300 --> 00:03:10,866
data set dollar level.

62
00:03:10,866 --> 00:03:11,666
All right.

63
00:03:11,666 --> 00:03:13,500
And the third parameter is the step.

64
00:03:13,500 --> 00:03:17,866
So that's where we increase the resolution
and make our fitting curve smoother.

65
00:03:18,133 --> 00:03:21,100
Because here
we're going to take a step of 0.1.

66
00:03:21,100 --> 00:03:25,466
And therefore 90 levels will be created
here from 1 to 10 incremented by 0.1.

67
00:03:26,000 --> 00:03:27,333
All right. So that's actually done.

68
00:03:27,333 --> 00:03:30,333
And now we need to replace data
set dollar level here.

69
00:03:30,333 --> 00:03:33,333
That originally
took the ten levels of our data set.

70
00:03:33,366 --> 00:03:35,433
So we are replacing that by x grid.

71
00:03:37,333 --> 00:03:38,466
And same here.

72
00:03:38,466 --> 00:03:42,600
We need to replace data
set here by a new data frame.

73
00:03:42,600 --> 00:03:47,100
Because you know this new data argument
here is expecting a data frame here.

74
00:03:47,233 --> 00:03:49,766
So we cannot replace it directly
by x grid here.

75
00:03:49,766 --> 00:03:52,433
Because X grid is not a data
frame. It's a sequence.

76
00:03:52,433 --> 00:03:54,033
That is it's a vector.

77
00:03:54,033 --> 00:03:56,266
So what we need to do here
is use this little trick.

78
00:03:56,266 --> 00:03:58,166
Again. Don't worry it's quite simple.

79
00:03:58,166 --> 00:04:02,900
We need to use this data
frame data dot frame command here.

80
00:04:02,900 --> 00:04:05,633
That will actually create a data frame.

81
00:04:05,633 --> 00:04:09,533
And in parentheses we're going to specify
that we want to create a data frame

82
00:04:09,766 --> 00:04:11,100
of new levels.

83
00:04:11,100 --> 00:04:14,500
So I'm taking the variable level here
and then equals.

84
00:04:14,500 --> 00:04:17,033
And that's where you put x grid.

85
00:04:17,033 --> 00:04:20,966
Because you know by doing this data
frame level equals x grid.

86
00:04:21,300 --> 00:04:24,300
We are just creating
a new column of levels

87
00:04:24,300 --> 00:04:28,100
containing all the levels in this sequence
X grid here of levels.

88
00:04:28,566 --> 00:04:29,566
And that's it.

89
00:04:29,566 --> 00:04:31,766
This new code section is ready to plot.

90
00:04:31,766 --> 00:04:34,733
Your regression
model results in higher resolution

91
00:04:34,733 --> 00:04:39,700
and actually we're going to specify here
that it's for higher resolution

92
00:04:40,766 --> 00:04:43,200
and smoother curve.

93
00:04:43,200 --> 00:04:44,600
All right. And that's actually ready.

94
00:04:44,600 --> 00:04:46,466
So you can try it on either

95
00:04:46,466 --> 00:04:49,466
you know your polynomial regression model
that we made in this section.

96
00:04:49,733 --> 00:04:51,566
Or you can use it on the future

97
00:04:51,566 --> 00:04:54,333
nonlinear regression models
that we're about to build.

98
00:04:54,333 --> 00:04:57,500
And you will see the difference
between these two.

99
00:04:57,533 --> 00:05:00,133
But then if you want a more simple code,
you can use this one.

100
00:05:00,133 --> 00:05:04,833
Or if you have for example, a data set
with 100 observations incremented by one,

101
00:05:04,966 --> 00:05:08,333
then this is the code you need to execute,
because then you wouldn't need a

102
00:05:08,366 --> 00:05:11,666
no point one step to build your
different points of your fitting curve.

103
00:05:12,233 --> 00:05:14,233
All right. So now the template is ready.

104
00:05:14,233 --> 00:05:15,900
We are actually ready to use it

105
00:05:15,900 --> 00:05:19,733
for the next nonlinear regression models
that we're about to build.

106
00:05:19,966 --> 00:05:21,800
We will do that in the next sections.

107
00:05:21,800 --> 00:05:24,866
And you're going to see how it will be so
efficient at building this.
