3
3
How to handle rolling time series
4
4
=================================
5
5
6
- In many application with time series on real-world problems, the "time" column
7
- (we will call it time in the following, although it can be anything)
8
- gives a certain sequential order to the data. We can exploit this sequence to generate
9
- more input data out of single time series, by *rolling * over the data.
10
-
11
- Imagine the following situation: you have the data of EEG measurements, that
12
- you want to use to classify patients into healthy and not healthy (we oversimplify the problem here).
13
- You have e.g. 100 time steps of data, so you can extract features that may forecast the healthiness
14
- of the patients. But what would happen if you had only the recorded measurement for 50 time steps?
15
- The patients would be as healthy as with 100 time steps. So you can easily increase the amount of
16
- training data by reusing time series cut into smaller pieces.
17
-
18
- Another example is streaming data, e.g. in Industry 4.0 applications. Here you typically get one
19
- new data row at a time and use this to predict machine failures for example. To train you model,
6
+ Lets assume that we have a DataFrame of one of the tsfresh :ref: `data-formats-label `.
7
+ The "sort" column of such a container gives a sequential state to the individual measurements.
8
+ In the case of time series this can be the *time * dimension while in the case of spectra the order is given by the
9
+ *wavelength * or *frequency * dimensions.
10
+ We can exploit this sequence to generate more input data out of single time series, by *rolling * over the data.
11
+
12
+ Imagine the following situation:
13
+ You have the data of certain sensors (e.g. EEG measurements) as the base to classify patients into a healthy and not
14
+ healthy group (we oversimplify the problem here).
15
+ Lets say you have sensor data of 100 time steps, so you may extract features for the forecasting of the patients
16
+ healthiness by a classification algorithm.
17
+ If you also have measurements of the healthiness for those 100 time steps (this is the target vector), then you could
18
+ predict the healthiness of the patient in every time step, which essentially states a time series forecasting problem.
19
+ So, to do that, you want to extract features in every time step of the original time series while for example looking at
20
+ the last 10 steps.
21
+ A rolling mechanism creates such time series for every time step by creating sub time series of the sensor data of the
22
+ last 10 time steps.
23
+
24
+ Another example can be found in streaming data, e.g. in Industry 4.0 applications.
25
+ Here you typically get one new data row at a time and use this to for example predict machine failures. To train your model,
20
26
you could act as if you would stream the data, by feeding your classifier the data after one time step,
21
27
the data after the first two time steps etc.
22
28
23
29
Both examples imply, that you extract the features not only on the full data set, but also
24
- on all temporal coherent subsets of data, which is the process of *rolling *. You can do this easily,
25
- by calling the function :func: `tsfresh.utilities.dataframe_functions.roll_time_series `.
30
+ on all temporal coherent subsets of data, which is the process of *rolling *. In tsfresh, this is implemented in the
31
+ function :func: `tsfresh.utilities.dataframe_functions.roll_time_series `.
26
32
27
33
The rolling mechanism takes a time series :math: `x` with its data rows :math: `[x_1 , x_2 , x_3 , ..., x_n]`
28
34
and creates :math: `n` new time series :math: `\hat x^k`, each of them with a different consecutive part
@@ -31,8 +37,7 @@ of :math:`x`:
31
37
.. math ::
32
38
\hat x^k = [x_k, x_{k-1 }, x_{k-2 }, ..., x_1 ]
33
39
34
- To see what this does in real-world applications, we look into the following example data frame (we show only one
35
- possible data format, but rolling works on all 3 data formats :ref: `data-formats-label `):
40
+ To see what this does in real-world applications, we look into the following example flat DataFrame in tsfresh format
36
41
37
42
+----+------+----+----+
38
43
| id | time | x | y |
@@ -50,9 +55,13 @@ possible data format, but rolling works on all 3 data formats :ref:`data-formats
50
55
| 2 | t9 | 11 | 13 |
51
56
+----+------+----+----+
52
57
53
- where you have measured two values (x and y) for two different entities (1 and 2) in 4 or 2 time steps.
58
+ where you have measured the values from two sensors x and y for two different entities (id 1 and 2) in 4 or 2 time
59
+ steps (t1 to t9).
54
60
55
- If you set `rolling ` to 0, the feature extraction works on
61
+ Now, we can use :func: `tsfresh.utilities.dataframe_functions.roll_time_series ` to get consecutive sub-time series.
62
+ E.g. if you set `rolling ` to 0, the feature extraction works on the original time series without any rolling.
63
+
64
+ So it extracts 2 set of features,
56
65
57
66
+----+------+----+----+
58
67
| id | time | x | y |
76
85
| 2 | t9 | 11 | 13 |
77
86
+----+------+----+----+
78
87
79
- So it extracts 2 set of features.
80
-
81
88
If you set rolling to 1, the feature extraction works with all of the following time series:
82
89
83
90
+----+------+----+----+
@@ -164,4 +171,7 @@ If you set rolling to -1, you end up with features for the time series, rolled i
164
171
| 2 | t8 | 10 | 12 |
165
172
+----+------+----+----+
166
173
| 2 | t9 | 11 | 13 |
167
- +----+------+----+----+
174
+ +----+------+----+----+
175
+
176
+ We only gave an example for the flat DataFrame format, but rolling actually works on all 3 :ref: `data-formats-label `
177
+ that are supported by tsfresh.
0 commit comments