WEBVTT - This file was automatically generated by VIMEO

0
00:00:07.690 --> 00:00:08.130
Hi.

1
00:00:08.130 --> 00:00:13.030
In this video we will learn how to parameterize the notebook and how to

2
00:00:13.050 --> 00:00:16.850
run and export it from Python. In some case,

3
00:00:17.310 --> 00:00:21.690
you may want to run the same notebook for multiple values of some

4
00:00:21.800 --> 00:00:26.370
parameter, and you would like to have separate H T M L reports. For example,

5
00:00:27.990 --> 00:00:32.690
you may want to execute same analysis on multiple segments of customers or

6
00:00:33.170 --> 00:00:36.930
multiple countries. If you are working from the ui,

7
00:00:37.270 --> 00:00:42.180
the solution for this is quite easy. You will set up in the notebook.

8
00:00:42.440 --> 00:00:45.980
The best is at the beginning, the variables, uh,

9
00:00:45.980 --> 00:00:48.020
which you want to use as parameters.

10
00:00:48.850 --> 00:00:52.590
And then you execute and export the notebook as you change its values.

11
00:00:54.570 --> 00:00:58.270
In the case, when you have just one or few parameters, it is fine,

12
00:00:59.210 --> 00:01:00.470
but when you have more of them,

13
00:01:00.970 --> 00:01:04.390
it is preferred to put the parameters in a separate file.

14
00:01:04.690 --> 00:01:09.270
And then in the notebook, you just read the file and extract these parameters,

15
00:01:09.530 --> 00:01:13.980
uh, from the file. YAML files, uh,

16
00:01:13.980 --> 00:01:17.500
require a bit of formatting, uh, but it is very easy to use.

17
00:01:18.210 --> 00:01:22.880
This method of parameters in a separate YAML file

18
00:01:23.060 --> 00:01:27.840
is also preferred when you want to do some automation where you will not

19
00:01:27.870 --> 00:01:30.440
execute and export the notebook from the ui,

20
00:01:30.900 --> 00:01:32.920
but from the terminal or python code.

21
00:01:34.430 --> 00:01:36.130
Now let's check our configuration,

22
00:01:36.130 --> 00:01:40.130
the YAML file with the parameters and let's adapt our notebook accordingly.

23
00:01:43.620 --> 00:01:45.430
Here is the config of the yamo file.

24
00:01:52.280 --> 00:01:56.940
We can parameterize if to fit the intercept or not when fitting

25
00:01:57.120 --> 00:02:00.960
the regression model and the alpha parameter in the chart.

26
00:02:11.010 --> 00:02:12.550
Now let's adapt the notebook.

27
00:02:15.330 --> 00:02:16.790
We have to import the yamo package.

28
00:02:23.840 --> 00:02:26.330
Then we load the yamo config file.

29
00:02:30.970 --> 00:02:33.310
We use the safe lot method from yaml.

30
00:02:55.770 --> 00:02:59.300
Then we extract from the config these parameters.

31
00:03:22.520 --> 00:03:27.350
After you load the config file to the config variable. Uh,

32
00:03:27.410 --> 00:03:30.190
config is basically only a Python dictionary.

33
00:03:45.330 --> 00:03:50.300
Okay? And now we have to change, uh, the variables here.

34
00:03:51.080 --> 00:03:51.913
We

35
00:03:59.660 --> 00:04:02.580
have to replace the value for alpha

36
00:04:09.350 --> 00:04:12.050
and in the model, the fit intercept,

37
00:04:25.380 --> 00:04:29.330
and we can create another section here. For example,

38
00:04:30.240 --> 00:04:31.330
loading the config.

39
00:04:40.650 --> 00:04:41.483
Okay,

40
00:04:45.570 --> 00:04:46.630
now let's run it.

41
00:05:11.620 --> 00:05:12.550
Okay, everything works.

42
00:05:21.680 --> 00:05:23.020
Now imagine, uh,

43
00:05:23.020 --> 00:05:27.740
that we would like to create reports for combination of two values for

44
00:05:27.880 --> 00:05:32.060
fit intercept and five for alpha. That makes 10 reports.

45
00:05:33.180 --> 00:05:36.440
We want to have the H T M L file and also the notebook for each.

46
00:05:36.710 --> 00:05:38.800
That is altogether 20 files.

47
00:05:39.950 --> 00:05:43.400
This is a lot of manual work because there are multiple steps

48
00:05:45.210 --> 00:05:47.870
you have to change manually. The configuration file,

49
00:05:48.670 --> 00:05:51.970
you have to execute the notebook, you have to export it,

50
00:05:53.310 --> 00:05:56.090
and then you have to rename the notebook and start again.

51
00:05:58.590 --> 00:06:02.890
We can create a simple script which automates execution, exporting,

52
00:06:02.990 --> 00:06:06.910
and renaming step. It'll have just two parameters.

53
00:06:07.530 --> 00:06:09.030
The configuration file path.

54
00:06:09.460 --> 00:06:14.430
That means we can prepare multiple configuration files advanced before launching

55
00:06:14.430 --> 00:06:18.380
the script and a name of newly created notebook.

56
00:06:20.860 --> 00:06:25.060
I have created this script already, so let's see how it works.

57
00:06:26.520 --> 00:06:29.980
Before we use it, we have to do one more thing in the notebook,

58
00:06:30.240 --> 00:06:34.500
and that is to create a variable config path. In the first cell of the notebook,

59
00:06:43.680 --> 00:06:46.710
we'll input the value for our configuration file,

60
00:06:51.390 --> 00:06:53.210
and let's change it also Here,

61
00:06:59.790 --> 00:07:00.720
save the notebook,

62
00:07:08.430 --> 00:07:13.210
the file. What we'll be using is this one, execute, export, and B pi.

63
00:07:13.940 --> 00:07:14.773
Let's run it.

64
00:07:20.930 --> 00:07:22.980
This is the command item.

65
00:07:23.960 --> 00:07:28.220
Then the name of our script parameter C uh,

66
00:07:28.220 --> 00:07:30.540
stands for the configuration file path,

67
00:07:31.530 --> 00:07:35.790
and the parameter n stands for the name of our newly created notebook.

68
00:07:49.500 --> 00:07:53.310
Okay, it was down. Now let's explain that script

69
00:08:02.330 --> 00:08:06.990
in the notebook we have in the first cell, and it has to be in the first cell,

70
00:08:07.500 --> 00:08:10.670
both where we read the pass to configuration file.

71
00:08:11.510 --> 00:08:15.200
This is how the NB parameterized library works. Uh,

72
00:08:15.200 --> 00:08:18.960
this is the library which handles the change of parameters in the notebook.

73
00:08:19.650 --> 00:08:20.483
For this library,

74
00:08:20.730 --> 00:08:25.590
the only variables it can access and change are the variables in the first

75
00:08:25.740 --> 00:08:26.790
cell of the notebook.

76
00:08:31.150 --> 00:08:35.280
Then in the script, we input two parameters, pass to configuration file,

77
00:08:36.140 --> 00:08:38.760
and the name of our newly created notebook.

78
00:08:39.190 --> 00:08:41.680
This will be also the name of the exported version.

79
00:08:46.120 --> 00:08:49.690
Then we read the notebook, uh, to a variable.

80
00:08:51.370 --> 00:08:53.070
We extract its parameters

81
00:08:55.530 --> 00:08:58.550
and we read and replace the parameter values.

82
00:09:00.220 --> 00:09:04.320
Notice that config path is the variable name in the notebook

83
00:09:05.280 --> 00:09:08.260
and path config is the parameter name of the script.

84
00:09:12.190 --> 00:09:13.680
Then we execute the notebook,

85
00:09:17.480 --> 00:09:22.460
then we save the executed notebook with the new name.

86
00:09:25.090 --> 00:09:29.950
And lastly, we export the notebook to H T M L file with embedded, uh,

87
00:09:29.950 --> 00:09:32.710
table of contents and pictures and charts.

88
00:09:36.190 --> 00:09:40.770
In our next video, we will learn how to embed H T M L into our notebook.
