1
00:00:05,260 --> 00:00:09,220
In this lecture I'm going to talk about Jupiter notebook.

2
00:00:09,310 --> 00:00:15,840
Occasionally I get this strange question from students asking why I don't do things in Jupiter or notebook.

3
00:00:15,970 --> 00:00:18,910
Let me explain why I think this is strange.

4
00:00:18,910 --> 00:00:24,550
Firstly it's my position that it's completely unnecessary and actually doesn't change anything.

5
00:00:24,670 --> 00:00:26,810
To use Jupiter notebook or not.

6
00:00:27,160 --> 00:00:33,450
Let me repeat that using Jupiter notebook is exactly the same as not using Jupiter notebook.

7
00:00:33,460 --> 00:00:36,580
There's no difference other than the fact that it looks different.

8
00:00:36,970 --> 00:00:39,940
In other words the screen is a different color.

9
00:00:39,940 --> 00:00:43,600
Obviously such a difference is trivial in this lecture.

10
00:00:43,600 --> 00:00:46,230
I'm going to demonstrate how that's the case

11
00:00:51,360 --> 00:00:58,050
one major reason I dislike Jupiter notebook is because it causes too many students to be unaware of

12
00:00:58,050 --> 00:01:00,080
how Python really works.

13
00:01:00,210 --> 00:01:06,060
If you're only comfortable inside notebook and when you see Python code in a text file or anywhere else

14
00:01:06,390 --> 00:01:10,110
and you get scared or intimidated that's not good.

15
00:01:10,110 --> 00:01:14,820
That Python code that's in the text file is exactly the same as what would be in the notebook.

16
00:01:14,820 --> 00:01:17,640
There's really nothing scary about it.

17
00:01:17,640 --> 00:01:24,970
Programmers working at real jobs eventually need to write code that's going to be deployed and run automatically.

18
00:01:25,140 --> 00:01:31,580
In other words your final code is going to sit in a python file that runs by itself without you put

19
00:01:31,590 --> 00:01:33,300
a notebook.

20
00:01:33,300 --> 00:01:39,330
So if you're going to have any hope of using these skills in a real job you had better be comfortable

21
00:01:39,330 --> 00:01:43,260
with writing Python code outside of Jupiter notebook.

22
00:01:43,410 --> 00:01:49,170
You would also better be aware that there is actually zero difference between writing code in a Jupiter

23
00:01:49,200 --> 00:01:52,290
a notebook and writing code in Python or the console

24
00:01:57,360 --> 00:02:02,930
here's one example I like of how you might use python in the quote unquote real world.

25
00:02:03,480 --> 00:02:09,200
Let's say you write a script that e-mails your boss to tell him you're going to be late for work and

26
00:02:09,210 --> 00:02:14,250
let's say you don't actually want to send this email manually but you want it to get sent automatically

27
00:02:14,250 --> 00:02:20,220
every Friday morning so that your boss doesn't yell at you for coming into work late after you a party

28
00:02:20,220 --> 00:02:20,700
too hard.

29
00:02:20,700 --> 00:02:22,260
Thursday night.

30
00:02:22,260 --> 00:02:24,210
Well that's very simple.

31
00:02:24,210 --> 00:02:28,830
All I have to do is on my server create what's called a cron tab in it.

32
00:02:29,160 --> 00:02:35,010
I just enter the code for when I want this command to run and then to the right of that I specify the

33
00:02:35,010 --> 00:02:37,080
command that I want to run.

34
00:02:37,170 --> 00:02:38,730
That's just Python space.

35
00:02:38,760 --> 00:02:44,610
And then the script name as you can see it's simply how you would run this python scripts from the command

36
00:02:44,610 --> 00:02:45,630
line.

37
00:02:45,810 --> 00:02:52,440
And now every Friday at nine forty five a.m. This script is going to send the same email to your boss.

38
00:02:52,440 --> 00:02:55,230
Tell him you'll be late.

39
00:02:55,240 --> 00:02:56,770
Well let's not get off track here.

40
00:02:56,770 --> 00:03:06,720
The point of this is you really don't want to be using Jupiter notebook for something like this.

41
00:03:06,840 --> 00:03:12,020
I think one perceived advantage of Jupiter notebook is that you can see the results of intermediate

42
00:03:12,030 --> 00:03:13,830
calculations.

43
00:03:13,830 --> 00:03:20,190
However this is merely a perceived advantage and not a real advantage because you can do the exact same

44
00:03:20,190 --> 00:03:26,300
thing even when you're not inside notebook firstly as I'm sure you've seen by now.

45
00:03:26,300 --> 00:03:31,030
I Python also prints out the results after you enter a command.

46
00:03:31,130 --> 00:03:37,550
I python is called a repo which stands for read Val print loop and that's generally what they all do.

47
00:03:37,580 --> 00:03:43,910
No matter what language you're in so whether that's Python Ruby HP or any other language.

48
00:03:44,090 --> 00:03:46,040
The keyword here is print.

49
00:03:46,040 --> 00:03:47,540
Why is that.

50
00:03:47,540 --> 00:03:54,270
Well one of my golden rules for writing and debugging code is When in doubt print it out.

51
00:03:54,320 --> 00:03:59,300
I can't tell you how many times I've gotten a question on the Q and A when it could have been easily

52
00:03:59,300 --> 00:04:03,130
answered by inserting a print statement into the existing code

53
00:04:08,370 --> 00:04:08,730
anyway.

54
00:04:08,730 --> 00:04:11,400
What's the point of this long discussion about printing things out.

55
00:04:12,180 --> 00:04:17,790
Well it's that if you think Jupiter notebook is the only program that helps you do this you need to

56
00:04:17,790 --> 00:04:19,960
expand your horizons a little bit.

57
00:04:20,070 --> 00:04:25,740
You should in fact always be doing this if you're not using an abundant amount of print statements while

58
00:04:25,740 --> 00:04:28,560
coding you are not doing it right.

59
00:04:28,560 --> 00:04:31,370
Remember programming is not philosophy.

60
00:04:31,530 --> 00:04:34,290
You're not supposed to be running a program in your head.

61
00:04:34,290 --> 00:04:40,390
That's like trying to do long division in your head when you have a calculator in your hand so just

62
00:04:40,390 --> 00:04:43,100
by printing things out you can be more efficient.

63
00:04:43,390 --> 00:04:49,390
Stop trying to guess what a program will do and just let the program itself tell you what it's doing.

64
00:04:49,390 --> 00:04:52,990
The key takeaway here is you should always be printing things out.

65
00:04:53,020 --> 00:04:59,200
The fact that Jupiter notebook shows you the result of each block of code is not simply a happy surprise

66
00:05:04,250 --> 00:05:10,250
but another important lesson here is that if you want to use Jupiter notebook there is absolutely nothing

67
00:05:10,250 --> 00:05:12,160
stopping you from doing so.

68
00:05:12,320 --> 00:05:19,730
In other words using Jupiter notebook is 100 percent compatible with everything we are already doing.

69
00:05:19,760 --> 00:05:27,080
In fact if you recall your goal in these courses is not to run my code but to write your own code and

70
00:05:27,080 --> 00:05:34,040
of course since it's your code you can write a however you want including Jupiter notebook in the rest

71
00:05:34,040 --> 00:05:34,810
of his lecture.

72
00:05:34,820 --> 00:05:40,610
I'm going to prove to you that you can take any scripts from our course repository which we know runs

73
00:05:40,610 --> 00:05:47,420
in the console because that's how I always demonstrate it and show you that this exact same code runs

74
00:05:47,420 --> 00:05:49,250
in Jupiter notebook.

75
00:05:49,280 --> 00:05:49,850
Let's begin

76
00:05:56,730 --> 00:05:57,140
OK.

77
00:05:57,150 --> 00:06:02,440
So let's say I'm in the folder num pi class and I'm interested in the code inside.

78
00:06:02,460 --> 00:06:10,980
Classification example that pi as you can see what I have right now is this code inside a text editor.

79
00:06:10,980 --> 00:06:16,650
Now if you're not aware of what a text editor is it's just a program that shows you the contents of

80
00:06:16,650 --> 00:06:19,520
a text file and lets you edit those contents.

81
00:06:19,740 --> 00:06:22,830
It's the ideal program for writing code.

82
00:06:22,890 --> 00:06:28,290
Now occasionally if you're writing in a language like Java or swift you might want to use an idea.

83
00:06:28,440 --> 00:06:30,710
But even then it's totally optional.

84
00:06:30,780 --> 00:06:36,690
These days I prefer to write Java in a plain text editor like sublime text as well.

85
00:06:36,690 --> 00:06:42,580
In any case normally one does not need to use an idea for writing Python code.

86
00:06:42,930 --> 00:06:44,710
Now about Jupiter notebook.

87
00:06:44,850 --> 00:06:51,920
Well let's start up a Jupiter notebook so I'm gonna go Jupiter notebook.

88
00:06:53,640 --> 00:06:53,910
All right.

89
00:06:53,920 --> 00:07:00,630
So now I've got Jupiter notebook running so I'm going to start a new notebook.

90
00:07:01,040 --> 00:07:07,460
Also notice that we started the notebook in the same directory as the relevant python file so that's

91
00:07:07,460 --> 00:07:11,310
something you want to keep in mind for the future now at this point.

92
00:07:11,320 --> 00:07:17,690
What I'm going to do is I'm going to prove that everything in this python file works exactly the same

93
00:07:17,780 --> 00:07:23,490
in the notebook as it does in the console.

94
00:07:23,640 --> 00:07:29,020
So let's start with the inputs let's grab this one to

95
00:07:32,670 --> 00:07:39,830
all right paste that in run it so everything's fine so far.

96
00:07:39,830 --> 00:07:48,070
Now let's load in the data.

97
00:07:49,580 --> 00:07:51,640
We've loaded in the data.

98
00:07:51,830 --> 00:07:53,450
Now I'm not sure what its type is.

99
00:07:53,480 --> 00:07:57,810
So I can check it by using the type function.

100
00:07:58,010 --> 00:07:58,820
So let me try that

101
00:08:03,840 --> 00:08:07,290
cool so I get SDK learned that you tells that bunch.

102
00:08:07,290 --> 00:08:12,710
So that's the type of the variable data now.

103
00:08:12,710 --> 00:08:19,080
Previously you recall that we did this example in Python but as you can see the result is the same and

104
00:08:19,090 --> 00:08:26,590
you put a notebook alternatively if you wanted to run this python file in the console so you wanted

105
00:08:26,590 --> 00:08:29,840
to type let's say

106
00:08:39,210 --> 00:08:46,110
so let's say you wanted to type in Python classification example that pi then you could just add some

107
00:08:46,110 --> 00:08:54,050
print statements if you wanted to show those same lines while this file was running.

108
00:08:54,060 --> 00:08:58,980
Now I'm not going to go through such elaborate detail for the rest of this example since you've already

109
00:08:58,980 --> 00:08:59,490
seen it.

110
00:08:59,850 --> 00:09:01,770
So let's just get through the rest line by line

111
00:09:05,810 --> 00:09:14,130
let's say I want to check out the keys in the data variable OK looks good so far.

112
00:09:15,620 --> 00:09:21,460
Let's check the shape of the data actually be ok.

113
00:09:21,510 --> 00:09:24,550
Looks good so far.

114
00:09:24,630 --> 00:09:25,900
Check the target's

115
00:09:29,970 --> 00:09:30,460
still.

116
00:09:30,550 --> 00:09:37,190
What we expect the target names.

117
00:09:37,210 --> 00:09:38,070
Looks good

118
00:09:41,360 --> 00:09:42,940
target shape.

119
00:09:42,980 --> 00:09:44,700
It should be five sixty nine.

120
00:09:44,750 --> 00:09:49,400
Yeah let's check out the feature names

121
00:09:52,720 --> 00:09:53,410
OK.

122
00:09:54,010 --> 00:09:56,880
That's the same as well.

123
00:09:56,950 --> 00:09:58,960
Now let's do our train test split

124
00:10:03,770 --> 00:10:06,160
OK.

125
00:10:06,360 --> 00:10:10,090
Now let's instantiate and fit our model

126
00:10:15,510 --> 00:10:16,010
all right.

127
00:10:16,680 --> 00:10:19,980
Now let's check the train score

128
00:10:23,630 --> 00:10:24,910
and the test score.

129
00:10:30,310 --> 00:10:35,320
All right now let's see how we can make new predictions

130
00:10:38,780 --> 00:10:46,830
S.C. how if you assign to a variable it doesn't print the result but if you have an expression then

131
00:10:46,830 --> 00:10:50,770
it does print the result.

132
00:10:51,060 --> 00:10:58,350
So there are some predictions and this was an alternative way to calculate the accuracy of the predictions.

133
00:10:58,560 --> 00:11:00,980
So we get the same answer as before.

134
00:11:01,440 --> 00:11:08,880
And we also have this other example where we can use a neural network to do the same thing.

135
00:11:09,030 --> 00:11:24,040
So let's build the model train it and print the train score and let's print the test scores well.

136
00:11:24,080 --> 00:11:24,390
All right.

137
00:11:24,410 --> 00:11:37,530
So everything works the exact same way as it does without using notebook.

138
00:11:37,550 --> 00:11:46,010
Now another thing I could have done was I could have just taken this whole thing and copied and pasted

139
00:11:46,010 --> 00:11:47,750
it in and run it.

140
00:11:47,750 --> 00:11:51,670
So that's another possible thing you can do.

141
00:11:52,070 --> 00:11:55,940
But the downside of that is you don't get to see the intermediate outputs.

142
00:11:55,940 --> 00:12:00,780
But again that's what print statements are for.

143
00:12:00,930 --> 00:12:01,290
All right.

144
00:12:01,290 --> 00:12:04,470
So what can we conclude from this exercise.

145
00:12:04,470 --> 00:12:11,100
Well we can see that this code runs exactly the same inside you put a notebook as it does everywhere

146
00:12:11,100 --> 00:12:12,240
else.

147
00:12:12,240 --> 00:12:18,870
That's why I always say Python code is Python code and no matter where it is if you want to use Jupiter

148
00:12:18,870 --> 00:12:24,140
notebook to run the course code there is absolutely nothing stopping you from doing so.
