php 获取时间序列,时间序列数据特征提取TsFresh--入门简介【附源码+数据】

本文介绍了如何使用TsFresh库从时间序列数据中提取特征,并展示了默认参数及不同参数设置(ComprehensiveFCParameters、EfficientFCParameters、MinimalFCParameters)下特征的提取与过滤过程。通过特征拓展和过滤,简化数据并为后续分析做准备。
摘要由CSDN通过智能技术生成

时间序列数据特征提取TsFresh–入门简介

简介

tsfresh用于从时间序列中提取特征。本篇主要介绍时间序列时间特征的拓展和过滤。编程环境jupyter notebook

源码和数据地址

TsFresh安装

pip install tsfresh

代码部分说明

数据下载

from tsfresh.examples.robot_execution_failures import download_robot_execution_failures, load_robot_execution_failures

download_robot_execution_failures()

timeseries, y = load_robot_execution_failures()

数据展示

timeseries.describe()

799f28e6a3bc957e5c372a1a4a5febee.png

y.head()

382a6d30df698a208876db69d2d0ee2f.png

从文件读取数据

import pandas as pd

import numpy as np

timeseries_csv = pd.read_csv('load_robot_execution_failures_timeseries.csv')

timeseries_csv.describe()

d956ab64414b35ecb51f26d2312c0a9c.png

y_csv = pd.read_csv('load_robot_execution_failures_y.csv',usecols = ['index','value'])

y_csv= pd.Series(np.array(y_csv['value']).tolist(),index =np.array(y_csv['index']).tolist())

y_csv.head()

a31283666798bd5a3eb6f007c79e2831.png

特征拓展

1、默认参数

from tsfresh.feature_extraction import extract_features

extracted_features_0 = extract_features(timeseries, column_id="id", column_sort="time")

extracted_features_0.shape

923b47a5f1ce648d501a298c2ffabfd4.png

2、ComprehensiveFCParameters参数

from tsfresh.feature_extraction import extract_features, ComprehensiveFCParameters

settings = ComprehensiveFCParameters()

extracted_features_1 = extract_features(timeseries, column_id="id", column_sort="time",default_fc_parameters=settings)

extracted_features_1.shape

d61848dfa359fd7def4ee6b7e4072749.png

3、EfficientFCParameters参数

from tsfresh.feature_extraction import extract_features, EfficientFCParameters

settings = EfficientFCParameters()

extracted_features_2 = extract_features(timeseries, column_id="id", column_sort="time",default_fc_parameters=settings)

extracted_features_2.shape

18b76b2b872451b4cee9448ff1a770b0.png

4、MinimalFCParameters参数

from tsfresh.feature_extraction import extract_features, MinimalFCParameters

settings = MinimalFCParameters()

extracted_features_3 = extract_features(timeseries, column_id="id", column_sort="time",default_fc_parameters=settings)

extracted_features_3.shape

7b423f3f8082b22d5f7a38c114112a03.png

特征过滤

1、默认参数

from tsfresh import select_features

from tsfresh.utilities.dataframe_functions import impute

impute(extracted_features_0)

features_filtered_0 = select_features(extracted_features_0, y) #特征选择

features_filtered_0.shape

c4b61fd8017afc8274e4293c8a07cc9e.png

2、ComprehensiveFCParameters参数

from tsfresh import select_features

from tsfresh.utilities.dataframe_functions import impute

impute(extracted_features_1)

features_filtered_1 = select_features(extracted_features_1, y) #特征选择

features_filtered_1.shape

43b53978483624ec0434c0a0c09b39e9.png

3、EfficientFCParameters参数

from tsfresh import select_features

from tsfresh.utilities.dataframe_functions import impute

impute(extracted_features_2)

features_filtered_2 = select_features(extracted_features_2, y) #特征选择

features_filtered_2.shape

113426baf22caa34ec49f245960b41ab.png

4、MinimalFCParameters参数

from tsfresh import select_features

from tsfresh.utilities.dataframe_functions import impute

impute(extracted_features_3)

features_filtered_3 = select_features(extracted_features_3, y) #特征选择

features_filtered_3.shape

9f92c9adbb3b7d4bfa05400d96ef294d.png

特征拓展和过滤同时进行

1、默认参数

from tsfresh import extract_relevant_features

features_filtered_direct_0 = extract_relevant_features(timeseries,y, column_id="id", column_sort="time")

features_filtered_direct_0.shape

057e131309cdf2605dc749860d02c2c5.png

2、ComprehensiveFCParameters参数

from tsfresh.feature_extraction import ComprehensiveFCParameters

from tsfresh import extract_relevant_features

settings = ComprehensiveFCParameters()

features_filtered_direct_1 = extract_relevant_features(timeseries,y, column_id="id", column_sort="time",default_fc_parameters=settings)

features_filtered_direct_1.shape

2ae2efd482d7d7d50d9230904e39d0e9.png

3、EfficientFCParameters参数

from tsfresh.feature_extraction import EfficientFCParameters

from tsfresh import extract_relevant_features

settings = EfficientFCParameters()

features_filtered_direct_2 = extract_relevant_features(timeseries,y, column_id="id", column_sort="time",default_fc_parameters=settings)

features_filtered_direct_2.shape

9f21b03337607edcf2ab69e023e5c003.png

4、MinimalFCParameters参数

from tsfresh.feature_extraction import MinimalFCParameters

from tsfresh import extract_relevant_features

settings = MinimalFCParameters()

features_filtered_direct_3 = extract_relevant_features(timeseries,y, column_id="id", column_sort="time",default_fc_parameters=settings)

features_filtered_direct_3.shape

baf85f148f15470e1bdd472c83afb43b.png

结论

通过拓展+滤波,和直接一次性滤波效果一致。

参考

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值