如何使用tsfresh python包从时间序列数据中提取特征?

2 python time-series feature-extraction tsfresh

我有一个列表列表,其中每个列表代表一个时间序列:

tsli=[[43,65,23,765,233,455,7,32,57,78,4,32],[34,32,565,87,23,86,32,56,32,57,78,32],[87,43,12,46,32,46,13,23,6,90,67,8],[1,2,3,3,4,5,6,7,8,9,0,9],[12,34,56,76,34,12,45,67,34,21,12,22]]
Run Code Online (Sandbox Code Playgroud)

我想使用代码使用 tsfresh 包从该数据集中提取特征:

import tsfresh
tf=tsfresh.extract_features(tsli)
Run Code Online (Sandbox Code Playgroud)

当我运行它时,我收到值错误,即:

> ValueError: You have to set the column_id which contains the ids of the different time series
But i don't know how to deal with this and how to define column id for this problem.
Run Code Online (Sandbox Code Playgroud)

编辑1: 正如建议的那样,我尝试将数据集转换为数据,然后尝试:

import tsfresh
df=pd.DataFrame(tsli)
tf=tsfresh.extract_features(df)
Run Code Online (Sandbox Code Playgroud)

但值错误是相同的

> ValueError: You have to set the column_id which contains the ids of the different time series
Run Code Online (Sandbox Code Playgroud)

任何资源或参考都会有所帮助。

谢谢

ilj*_*lja 6

首先你必须将你的转换list为 a dataframe,其中每个时间序列都有一个唯一的 id,例如

\n\n
df = pd.DataFrame()\nfor i, ts in enumerate(tsli):\n    data = [[x, i] for x in ts]\n    df = df.append(data, ignore_index=True)\ndf.columns = [\'value\', \'id\']\n
Run Code Online (Sandbox Code Playgroud)\n\n

在此输入图像描述...在此输入图像描述

\n\n

column_id现在您可以在创建的列上使用 tsfresh 和参数:

\n\n
tf=tsfresh.extract_features(df, column_id=\'id\')\n\n\n>> Feature Extraction: 100%|\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88| 5/5 [00:00<00:00, 36.83it/s]\n
Run Code Online (Sandbox Code Playgroud)\n\n

另一个例子:tsfresh 快速入门

\n

  • 不客气 :-) 是的,tsfresh 需要将所有时间序列“堆叠为单个时间序列”并用 id 分隔(因此是列)。这是因为如果您想进行多元时间序列分析,您仍然可以使用矩阵/二维数据帧。顺便说一句,您可以忽略索引。 (3认同)