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