1
00:00:00,000 --> 00:00:02,460
Let's take a look
at time series and

2
00:00:02,460 --> 00:00:05,835
the various attributes of
time series using Python.

3
00:00:05,835 --> 00:00:08,190
This notebook is
available as part of

4
00:00:08,190 --> 00:00:10,350
the course and I'll
provide a link to it.

5
00:00:10,350 --> 00:00:12,315
I recommend that you
watch this video first

6
00:00:12,315 --> 00:00:14,820
and then try the notebook
for yourself afterwards.

7
00:00:14,820 --> 00:00:17,280
I'll start by running
the nodes containing

8
00:00:17,280 --> 00:00:20,285
the imports as well as
a couple of helper functions.

9
00:00:20,285 --> 00:00:23,435
One to plot the series and
one to return a trend.

10
00:00:23,435 --> 00:00:27,150
So now, let's plot our first
very simple time series.

11
00:00:27,150 --> 00:00:28,545
Even though it's a straight line,

12
00:00:28,545 --> 00:00:30,735
it's also an example
of the time series.

13
00:00:30,735 --> 00:00:33,200
The x-axis in
this case is time and

14
00:00:33,200 --> 00:00:36,725
the y value is the value of
the function at that time.

15
00:00:36,725 --> 00:00:39,020
Next, we'll take a look at adding

16
00:00:39,020 --> 00:00:41,480
a seasonal pattern
to our time series.

17
00:00:41,480 --> 00:00:44,030
These functions contain
a seasonal pattern and

18
00:00:44,030 --> 00:00:47,255
then seasonality that just
uses the same pattern.

19
00:00:47,255 --> 00:00:49,340
We'll now plot that.

20
00:00:49,340 --> 00:00:50,990
As we investigate the graph,

21
00:00:50,990 --> 00:00:53,375
we can see clear peaks
and troughs.

22
00:00:53,375 --> 00:00:55,185
But in addition to that,

23
00:00:55,185 --> 00:00:57,665
there are smaller,
regular spikes.

24
00:00:57,665 --> 00:01:00,035
This could be seen as
a rough simulation

25
00:01:00,035 --> 00:01:01,610
of a seasonal value.

26
00:01:01,610 --> 00:01:04,130
For example, maybe
profits for shop that

27
00:01:04,130 --> 00:01:06,635
are negative on the day
the store is closed,

28
00:01:06,635 --> 00:01:08,400
peaking a little the day after,

29
00:01:08,400 --> 00:01:09,785
decaying during the week

30
00:01:09,785 --> 00:01:12,245
and then peaking
again on the weekend.

31
00:01:12,245 --> 00:01:15,890
What if we now add a trend
to this so that the seasonal

32
00:01:15,890 --> 00:01:17,450
data while still following the

33
00:01:17,450 --> 00:01:19,755
pattern increases over time?

34
00:01:19,755 --> 00:01:23,250
Maybe simulating a growing
business so when we plot it,

35
00:01:23,250 --> 00:01:25,040
we'll see the same pattern but

36
00:01:25,040 --> 00:01:27,710
with an overall upward trend.

37
00:01:27,710 --> 00:01:30,320
What if we now add
another feature that's

38
00:01:30,320 --> 00:01:32,440
common in time series, noise?

39
00:01:32,440 --> 00:01:33,930
Here's a function that add

40
00:01:33,930 --> 00:01:35,990
some noise to a series and when

41
00:01:35,990 --> 00:01:37,655
we call that and plot the results

42
00:01:37,655 --> 00:01:39,635
and their impact on
our time series,

43
00:01:39,635 --> 00:01:42,110
we now get a very noisy series,

44
00:01:42,110 --> 00:01:43,730
but one which follows

45
00:01:43,730 --> 00:01:46,220
the same seasonality
as we saw earlier.

46
00:01:46,220 --> 00:01:48,230
It's interesting
because at this point,

47
00:01:48,230 --> 00:01:50,240
the human eye may miss a lot of

48
00:01:50,240 --> 00:01:51,890
the seasonality data but

49
00:01:51,890 --> 00:01:54,690
a computer will hopefully
be able to spot it.

50
00:01:54,700 --> 00:01:58,175
Next we can explore a little bit
of Autocorrelation,

51
00:01:58,175 --> 00:01:59,540
but first here are a couple of

52
00:01:59,540 --> 00:02:02,160
functions that can
add it for you.

53
00:02:02,320 --> 00:02:04,430
Here is where we add

54
00:02:04,430 --> 00:02:07,025
the autocorrelation to
the series and plot it.

55
00:02:07,025 --> 00:02:09,800
There are two different
autocorrelation functions and

56
00:02:09,800 --> 00:02:13,115
I'll plot both so that you
can see the effects of each.

57
00:02:13,115 --> 00:02:16,790
This one is particularly
interesting because you can see

58
00:02:16,790 --> 00:02:20,015
the repeated pattern
despite different scales.

59
00:02:20,015 --> 00:02:23,120
There is a pattern and then
a sharp fall off followed by

60
00:02:23,120 --> 00:02:25,145
the same pattern
on a smaller scale

61
00:02:25,145 --> 00:02:26,480
with the same fall off,

62
00:02:26,480 --> 00:02:29,460
which is then shrunk et cetera.

63
00:02:29,460 --> 00:02:32,435
If I change autocorrelation
functions and run it again,

64
00:02:32,435 --> 00:02:34,950
we can then see
the other function.

65
00:02:37,780 --> 00:02:41,400
Okay. Let's add some noise.

66
00:02:43,880 --> 00:02:53,620
Then we'll try another
autocorrelation and another.

67
00:03:00,260 --> 00:03:03,185
Now, let's add them to simulate

68
00:03:03,185 --> 00:03:05,450
a seasonal time series that

69
00:03:05,450 --> 00:03:08,495
has an impact full of events
that changes everything.

70
00:03:08,495 --> 00:03:10,640
For example, that might
be a financial series

71
00:03:10,640 --> 00:03:11,945
that shows seasonality,

72
00:03:11,945 --> 00:03:13,730
but then something changes like

73
00:03:13,730 --> 00:03:16,980
a failure of the business
or big news events.

74
00:03:26,570 --> 00:03:30,110
Now, I'm going to add
some impulses and plot them.

75
00:03:30,110 --> 00:03:32,490
Nothing too exciting here yet.

76
00:03:35,140 --> 00:03:39,230
But when I start adding
some autocorrelations to this,

77
00:03:39,230 --> 00:03:41,270
then we'll see some of
the behavior that we had

78
00:03:41,270 --> 00:03:43,550
discussed earlier where from

79
00:03:43,550 --> 00:03:46,010
our pulse we have
a decay away from it

80
00:03:46,010 --> 00:03:49,630
but the decay could be
interrupted by another pulse.

81
00:03:49,630 --> 00:03:53,430
This decay could be
autocorrelated so that after

82
00:03:53,430 --> 00:03:57,040
the pulse it decays but
then the decay autocorrelates.

83
00:03:57,040 --> 00:04:00,060
So we have these
decreasing curves.

84
00:04:01,760 --> 00:04:04,610
Hopefully this exploration of

85
00:04:04,610 --> 00:04:06,950
some synthetic data
to show some of

86
00:04:06,950 --> 00:04:09,050
the attributes of time-series was

87
00:04:09,050 --> 00:04:12,230
helpful for you to understand
some of the terminology.

88
00:04:12,230 --> 00:04:14,390
I have found that synthetic data

89
00:04:14,390 --> 00:04:16,580
like this is very useful if you

90
00:04:16,580 --> 00:04:18,020
want to learn how to use

91
00:04:18,020 --> 00:04:21,320
Machine Learning to understand
and predict on data.

92
00:04:21,320 --> 00:04:23,090
In the next lesson, you'll take

93
00:04:23,090 --> 00:04:24,860
the first steps
towards predicting

94
00:04:24,860 --> 00:04:26,060
the next values in

95
00:04:26,060 --> 00:04:28,870
a synthetic series before
later in the course,

96
00:04:28,870 --> 00:04:30,200
you'll start applying what you've

97
00:04:30,200 --> 00:04:32,640
learned to real-world data.