心跳信号分类预测-特征工程

本节的主要内容是对心跳信号时间序列数据的做特征工程,用到的时间序列特征处理工具是— Tsfresh(TimeSeries Fresh)。tsfresh是专门用于从时间序列中提取特征的工具(安装------pip install tsfresh)。这个工具包含很多计算函数,可以从多个维度对时间序列做处理。
例如:(索引自:原文链接:https://blog.csdn.net/yunini2/article/details/92805230)

tsfresh.feature_extraction.feature_calculators.abs_energy(x)
时间序列的平方和

tsfresh.feature_extraction.feature_calculators.absolute_sum_of_changes(x)
返回序列x的连续变化的绝对值之和

tsfresh.feature_extraction.feature_calculators.agg_autocorrelation(x, param)
计算聚合函数f_agg(例如方差或者均值)处理后的自相关性,在一定程度可以衡量数据的周期性质,l表示滞后值,如果某个l计算出的值比较大,表示改时序数据具有l周期性质。n是时间序列的长度, 是方差,μ表示均值

tsfresh.feature_extraction.feature_calculators.agg_linear_trend(x, param)
对时序分块聚合后(max, min, mean, meidan),然后聚合后的值做线性回归,算出 pvalue(),rvalue(相关系数), intercept(截距), slope(斜率), stderr(拟合的标准差)

tsfresh.feature_extraction.feature_calculators.approximate_entropy(x, m, r)
近似熵,用来衡量一个时间序列的周期性、不可预测性和波动性

tsfresh.feature_extraction.feature_calculators.ar_coefficient(x, param)
自回归模型系数,适用于极大似然估计的AR(k)模型,参数k是滞后项

tsfresh.feature_extraction.feature_calculators.augmented_dickey_fuller(x, param)
扩张的Dickey-Fuller检验(ADF)是在时间序列分析中用来辨识个别变数的样本资料是否存在单位根,返回的是测试统计量的值

tsfresh.feature_extraction.feature_calculators.autocorrelation(x, lag)
滞后lag的自相关系数

tsfresh.feature_extraction.feature_calculators.binned_entropy(x, max_bins)
把整个序列按值均分成max_bins个桶,然后把每个值放进相应的桶中,然后求熵。
表示落在第k个桶中的数占总体的比例。这个特征是为了衡量样本值分布的均匀度。
参数:x(pandas.Series) 需要计算特征的时间序列
   max_bins (int) 桶的数量

tsfresh.feature_extraction.feature_calculators.c3(x, lag)
衡量时序数据的非线性性

tsfresh.feature_extraction.feature_calculators.change_quantiles(x, ql, qh, isabs, f_agg) 先用ql和qh两个分位数在x中确定出一个区间,然后在这个区间里计算时序数据的均值、绝对值、连续变化值。
Parameters:
x (pandas.Series) – 时序数据
ql (float) – 分位数的下限
qh (float) – 分位数的上线
isabs (bool) – 使用使用绝对值
f_agg (str, name of a numpy function (e.g. mean, var, std, median)) – numpy自带的聚合函数(均值,方差,标准差,中位数)

tsfresh.feature_extraction.feature_calculators.cid_ce(x, normalize)
用来评估时间序列的复杂度,越复杂的序列有越多的谷峰。

tsfresh.feature_extraction.feature_calculators.count_above_mean(x)
大于均值的数的个数

tsfresh.feature_extraction.feature_calculators.count_below_mean(x)
小于均值的数的个数

tsfresh.feature_extraction.feature_calculators.cwt_coefficients(x, param)
计算Ricker小波的连续小波变化,又被成为“墨西哥帽小波”
采用所有不同宽度的数组,对每个不同宽度的数组进行一次cwt计算

tsfresh.feature_extraction.feature_calculators.energy_ratio_by_chunks(x, param)
计算块i在N个块的平方和,对整个级数求平方和的比率

tsfresh.feature_extraction.feature_calculators.fft_aggregated(x, param)
Returns the spectral centroid (mean)光谱矩心, variance方差, skew偏度, and kurtosis of the absolute fourier transform spectrum绝对傅里叶变换频谱的峰度.

tsfresh.feature_extraction.feature_calculators.fft_coefficient(x, param)
通过快速傅里叶变换算法计算一维离散傅里叶变换的傅里叶系数

tsfresh.feature_extraction.feature_calculators.first_location_of_maximum(x)
最大值第一次出现的位置

tsfresh.feature_extraction.feature_calculators.first_location_of_minimum(x)
最小值第一次出现的位置

tsfresh.feature_extraction.feature_calculators.has_duplicate(x)
有没有重复值,bool

tsfresh.feature_extraction.feature_calculators.has_duplicate_max(x)
最大值有没有重复, bool

tsfresh.feature_extraction.feature_calculators.has_duplicate_min(x)
最小值有没有重复, bool

tsfresh.feature_extraction.feature_calculators.index_mass_quantile(x, param)
这些应用特性计算相对指数i,其中q%的时间序列x位于i的左侧

tsfresh.feature_extraction.feature_calculators.kurtosis(x)
返回x的峰度(采用调整后的Fisher-Pearson标准化矩系数G2计算)

tsfresh.feature_extraction.feature_calculators.large_standard_deviation(x, r)
x的标准差是否大于r乘以最大值减最小值

tsfresh.feature_extraction.feature_calculators.last_location_of_maximum(x)
最大值最后出现的位置

tsfresh.feature_extraction.feature_calculators.last_location_of_minimum(x)
最小值最后出现的位置

tsfresh.feature_extraction.feature_calculators.length(x)
x的长度

tsfresh.feature_extraction.feature_calculators.linear_trend_timewise(x, param)
计算时间序列的值与从0到时间序列长度- 1之间的序列的线性最小二乘回归,特征假设信号是均匀采样的,不会使用时间戳来匹配模型,参数控制返回哪些特性。可能提取的属性:pvalue|rvalue|intercept|slope|stderr…

tsfresh.feature_extraction.feature_calculators.longest_strike_above_mean(x)
大于均值的最长连续子序列长度

tsfresh.feature_extraction.feature_calculators.longest_strike_below_mean(x)
小于均值的最长连续子序列长度

tsfresh.feature_extraction.feature_calculators.maximum(x)
最大值

tsfresh.feature_extraction.feature_calculators.mean(x)
均值

tsfresh.feature_extraction.feature_calculators.mean_abs_change(x)
连续变化值绝对值的均值

tsfresh.feature_extraction.feature_calculators.mean_change(x)
连续变化值的均值

tsfresh.feature_extraction.feature_calculators.median(x)
中位数

tsfresh.feature_extraction.feature_calculators.minimum(x)
最小值

tsfresh.feature_extraction.feature_calculators.number_crossing_m(x, m)
计算x与m的相交次数,相交被定义为:;两个序列值,第一个值比m小第二个值更大,反之亦然。如果把m设为0,得到0相交的数量。

tsfresh.feature_extraction.feature_calculators.number_cwt_peaks(x, n)
搜索X中不同的峰值,x被ricker小波平滑,宽度从1到n。返回的是在足够的宽度上出现峰的数量及SNR高信号噪声比?

tsfresh.feature_extraction.feature_calculators.number_peaks(x, n)
峰值个数

tsfresh.feature_extraction.feature_calculators.partial_autocorrelation(x, param)
指定滞后lag的偏自相关函数的值。lag : k

tsfresh.feature_extraction.feature_calculators.percentage_of_reoccurring_values_to_all_values(x)
出现超过1次的值的个数/总个数

tsfresh.feature_extraction.feature_calculators.quantile(x, q)
返回x中q的分位数,q% 小于分位数。

tsfresh.feature_extraction.feature_calculators.range_count(x, min, max)
x中在min和max之间的数的个数

tsfresh.feature_extraction.feature_calculators.ratio_beyond_r_sigma(x, r)
取值大于r倍标准差的比例

tsfresh.feature_extraction.feature_calculators.ratio_value_number_to_time_series_length(x)
把 x unique后的长度除以x原始长度 len(set(x))/len(x)

tsfresh.feature_extraction.feature_calculators.sample_entropy(x)

tsfresh.feature_extraction.feature_calculators.skewness(x)
返回x的偏度(采用调整后的Fisher-Pearson标准化矩系数G1计算)

tsfresh.feature_extraction.feature_calculators.standard_deviation(x)
标准差

tsfresh.feature_extraction.feature_calculators.sum_of_reoccurring_data_points(x)
出现过多次的点的个数

tsfresh.feature_extraction.feature_calculators.sum_of_reoccurring_values(x)
出现过多次的值的和

tsfresh.feature_extraction.feature_calculators.sum_values(x)
所有值的和

tsfresh.feature_extraction.feature_calculators.value_count(x, value)
x中值等于value的计数

tsfresh.feature_extraction.feature_calculators.variance(x)
方差

tsfresh.feature_extraction.feature_calculators.variance_larger_than_standard_deviation(x)
方差是否大于标准差

功能还是很齐全的。如果没有这个工具,在python中对dataframe数据做这样的计算,需要花费不少时间处理。所以这个工具的加入,能节省不少数据处理时间。

你可能感兴趣的:(算法,数据分析,数据挖掘,机器学习)