3
3
Data Formats
4
4
============
5
5
6
- tsfresh offers three different options to specify the time series data to be used in the :func: `tsfresh.extract_features `
7
- function. Irrespective of the input format, tsfresh will always return the calculated features in the same output format.
6
+ tsfresh offers three different options to specify the time series data to be used in the
7
+ :func: `tsfresh.extract_features ` function (and all utility functions that expect a time series, e.g. the
8
+ :func: `tsfresh.utilities.dataframe_functions.roll_time_series ` function).
9
+
10
+ Irrespective of the input format, tsfresh will always return the calculated features in the same output format
11
+ described below.
8
12
9
13
All three input format options consist of :class: `pandas.DataFrame ` objects. There are four important column types that
10
- make up those DataFrames:
14
+ make up those DataFrames. Each will be described with an example from the robot failures dataset
15
+ (see :ref: `quick-start-label `).
11
16
12
- Mandatory
17
+ Mandatory:
13
18
14
- :`column_id `: This column indicates which entities the time series belong to. Features will be extracted individually for each
15
- entity. The resulting feature matrix will contain one row per entity.
19
+ :`column_id `: This column indicates which entities the time series belong to. Features will be extracted individually
20
+ for each entity. The resulting feature matrix will contain one row per entity.
21
+ Each robot is a different entity, so each of it has a different id.
16
22
:`column_value `: This column contains the actual values of the time series.
23
+ This corresponds to the measured values for different the sensors on the robots.
17
24
18
- Optional (but strongly recommended to specify)
25
+ Optional (but strongly recommended to specify if you have this column):
19
26
20
- :`column_sort `: This column contains values which allow to sort the time series (e.g. time stamps). It is not required to
21
- have equidistant time steps or the same time scale for the different ids and/or kinds.
27
+ :`column_sort `: This column contains values which allow to sort the time series (e.g. time stamps). It is not required
28
+ to have equidistant time steps or the same time scale for the different ids and/or kinds.
22
29
If you omit this column, the DataFrame is assumed to be already sorted in increasing order.
30
+ The robot sensor measurements each have a time stamp which is used in this column.
31
+
32
+ Please note that none of the algorithms of tsfresh uses the actual values in this time column - but only their
33
+ sorting order.
23
34
24
- Optional
35
+ Optional:
25
36
26
37
:`column_kind `: This column indicates the names of the different time series types (E.g. different sensors in an
27
- industrial application). For each kind of time series the features are calculated individually.
38
+ industrial application as in the robot dataset).
39
+ For each kind of time series the features are calculated individually.
28
40
29
41
30
42
Important: None of these columns is allowed to contain any ``NaN ``, ``Inf `` or ``-Inf `` values.
31
43
32
- Now there are three slightly different input formats for the time series data :
44
+ In the following we describe the different input formats, that are build on those columns :
33
45
* A flat DataFrame
34
46
* A stacked DataFrame
35
47
* A dictionary of flat DataFrames
36
48
37
49
The difference between a flat and a stacked DataFrame is indicated by specifying or not specifying the parameters
38
- `column_value ` and `column_kind ` in the `extract_features ` function.
50
+ `column_value ` and `column_kind ` in the :func: `tsfresh.extract_features ` function.
51
+
52
+ If you do not know which one to choose, you probably want to try out the flat or stacked DataFrame.
39
53
40
54
Input Option 1. Flat DataFrame
41
55
------------------------------
42
56
43
- If both `column_value ` and `column_kind ` are set to ``None ``, the time series data is assumed to be in a flat
44
- DataFrame. This means that each different time series is saved as its own column.
57
+ If both `column_value ` and `column_kind ` are set to ``None ``, the time series data is assumed to be in a flat
58
+ DataFrame. This means that each different time series must be saved as its own column.
45
59
46
- Example: Imagine you record the values of time series x and y for different objects A and B for three different times t1, t2 and
47
- t3. Now you want to calculate some feature with tsfresh. Your resulting DataFrame has to look like this:
60
+ Example: Imagine you record the values of time series x and y for different objects A and B for three different
61
+ times t1, t2 and t3. Now you want to calculate some feature with tsfresh. Your resulting DataFrame may look
62
+ like this:
48
63
49
64
+----+------+----------+----------+
50
65
| id | time | x | y |
@@ -68,18 +83,18 @@ and you would pass
68
83
69
84
column_id= " id" , column_sort= " time" , column_kind= None , column_value= None
70
85
71
- to the extraction functions.
86
+ to the extraction functions, to extract features separately for all ids and separately for the x and y values .
72
87
73
88
Input Option 2. Stacked DataFrame
74
89
---------------------------------
75
90
76
91
If both `column_value ` and `column_kind ` are set, the time series data is assumed to be a stacked DataFrame.
77
- This means that there are no different columns for the different type of time series.
92
+ This means that there are no different columns for the different types of time series.
78
93
This representation has several advantages over the flat Data Frame.
79
94
For example, the time stamps of the different time series do not have to align.
80
95
81
96
It does not contain different columns for the different types of time series but only one
82
- value column and a kind column:
97
+ value column and a kind column. The example from above would look like this :
83
98
84
99
+----+------+------+----------+
85
100
| id | time | kind | value |
@@ -115,11 +130,14 @@ Then you would set
115
130
116
131
column_id= " id" , column_sort= " time" , column_kind= " kind" , column_value= " value"
117
132
133
+ to end up with the same extracted features as above.
134
+
135
+
118
136
Input Option 3. Dictionary of flat DataFrames
119
137
---------------------------------------------
120
138
121
- Instead of passing a DataFrame which must be split up by its different kinds, you can also give a dictionary mapping
122
- from the kind as string to a DataFrame containing only the time series data of that kind.
139
+ Instead of passing a DataFrame which must be split up by its different kinds by tsfresh , you can also give a
140
+ dictionary mapping from the kind as string to a DataFrame containing only the time series data of that kind.
123
141
So essentially you are using a singular DataFrame for each kind of time series.
124
142
125
143
The data from the example can be split into two DataFrames resulting in the following dictionary
@@ -163,7 +181,7 @@ The data from the example can be split into two DataFrames resulting in the foll
163
181
164
182
}
165
183
166
- tsfresh would be passed this dictionary and the following arguments
184
+ You would pass this dictionary to tsfresh together with the following arguments:
167
185
168
186
.. code :: python
169
187
@@ -186,5 +204,8 @@ It will always be a :class:`pandas.DataFrame` with the following layout
186
204
| B | ... | ... | ... | ... | ... | ... |
187
205
+----+-------------+-----+-------------+-------------+-----+-------------+
188
206
189
- where the x features are calculated using all x values (independently for A and B), y features using all y values and so
190
- on.
207
+ where the x features are calculated using all x values (independently for A and B), y features using all y values
208
+ and so on.
209
+
210
+ This form of DataFrame is also the expected input format to the feature selection algorithms (e.g. the
211
+ :func: `tsfresh.select_features ` function).
0 commit comments