【问题标题】:how to use tsfresh python package to extract features from time series data?如何使用 tsfresh python 包从时间序列数据中提取特征?
【发布时间】:2020-09-16 04:38:23
【问题描述】:

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

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]]

我想通过 tsfresh 包使用代码从这个数据集中提取特征:

import tsfresh
tf=tsfresh.extract_features(tsli)

当我运行它时,我收到了 Value 错误:

> 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.

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

import tsfresh
df=pd.DataFrame(tsli)
tf=tsfresh.extract_features(df)

但是值错误是一样的

> ValueError: You have to set the column_id which contains the ids of the different time series

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

谢谢

【问题讨论】:

  • Tsfresh 似乎使用数据帧作为数据格式,而不是列表。
  • 所以即使我将其转换为 df 那么如何为此设置列 ID?

标签: python time-series feature-extraction tsfresh


【解决方案1】:

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

df = pd.DataFrame()
for i, ts in enumerate(tsli):
    data = [[x, i] for x in ts]
    df = df.append(data, ignore_index=True)
df.columns = ['value', 'id']

...

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

tf=tsfresh.extract_features(df, column_id='id')


>> Feature Extraction: 100%|██████████| 5/5 [00:00<00:00, 36.83it/s]

另一个例子:tsfresh Quick Start

【讨论】:

  • 我有一个困惑,为什么我们有从 0 到 59 的索引,是否将所有时间序列作为单个时间序列?并感谢您的解决方案。
  • 不客气 :-) 是的,tsfresh 需要将所有时间序列“堆叠为单个时间序列”并用 id 分隔(因此是列)。那是因为如果您想进行多变量时间序列分析,您仍然可以使用矩阵/二维数据框。顺便说一句,您可以忽略索引。
  • 谢谢,帮了大忙 :)
猜你喜欢
  • 2020-04-26
  • 1970-01-01
  • 2023-02-22
  • 1970-01-01
  • 1970-01-01
  • 2019-07-09
  • 2020-07-17
  • 2020-03-20
  • 1970-01-01
相关资源
最近更新 更多