python - 为深度学习增强时间序列数据

标签 python pandas dataframe time-series data-augmentation

如果我想将深度学习应用于我目前拥有的传感器的数据集,我将需要相当多的数据,否则我们可能会出现过度拟合。不幸的是,传感器只激活了一个月,因此数据需要扩充。我目前有数据框形式的数据,如下所示:

index   timestamp              cas_pre        fl_rat         ...
0       2017-04-06 11:25:00    687.982849     1627.040283    ...
1       2017-04-06 11:30:00    693.427673     1506.217285    ...
2       2017-04-06 11:35:00    692.686310     1537.114807    ...
....
101003  2017-04-06 11:35:00    692.686310     1537.114807    ...

现在我想用 tsaug package 增加一些特定的列.增强可以采用以下形式:

my_aug = (    
    RandomMagnify(max_zoom=1.2, min_zoom=0.8) * 2
    + RandomTimeWarp() * 2
    + RandomJitter(strength=0.1) @ 0.5
    + RandomTrend(min_anchor=-0.5, max_anchor=0.5) @ 0.5
)

扩充库的文档继续以下面的方式使用扩充:

X_aug, Y_aug = my_aug.run(X, Y)

进一步调查 this站点,似乎扩充影响了 numpy 数组。虽然它声明这是一个多变量增强,但不确定它是如何有效发生的。

我想在 float 字列(例如 cas_prefl_rat)上应用这种一致的扩充,以便不偏离原始数据和每个列之间的关系列太多了。我不想应用它的行,例如 timestamp。我不确定如何在 Pandas 中执行此操作。

最佳答案

这是我的尝试:

#Convert Pandas dataframe to Numpy array and apply tsaug transformations

import numpy as np
import pandas as pd
from tsaug import TimeWarp, Crop, Quantize, Drift, Reverse

df = pd.DataFrame({"timestamp": [1, 2],"cas_pre": [687.982849, 693.427673], "fl_rat": [1627.040283, 1506.217285]})

my_aug = (    
    Drift(max_drift=(0.1, 0.5))
)

aug = my_aug.augment(df[["timestamp","cas_pre","fl_rat"]].to_numpy())

print("Input:")
print(df[["timestamp","cas_pre","fl_rat"]].to_numpy()) #debug
print("Output:")
print(aug)

控制台输出:

Input:
[[1.00000000e+00 6.87982849e+02 1.62704028e+03]
 [2.00000000e+00 6.93427673e+02 1.50621728e+03]]
Output:
[[1.00000000e+00 9.13389853e+02 2.03588979e+03]
 [2.00000000e+00 1.01536282e+03 1.43177109e+03]]

您可能需要将时间戳转换为数字。

您使用的 tsaug 函数似乎不存在,因此我仅将 drift() 用作示例。经过一些实验,默认情况下,TimeWarp() 不会影响时间戳(第 1 列),但 TimeWarp()*5 通过将每个时间戳克隆 5 次来插入新样本。

关于python - 为深度学习增强时间序列数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64382366/

相关文章:

python - 删除多索引和自动重命名列

python - 根据列对某些行赋予权重

Python——2.7 中没有的东西是 3.1 中的什么?很多东西都被向后移植了,什么不是?

Pandas 数据框分组并按工作日排序

python - TensorFlow 中简单前馈 NN 的 GPU 训练的高效示例实现?也许用 tf.data?

python - 无法将时间对象转换为 datetime64[ns]

python-2.7 - 使用 python 和 matplotlib 的时间线条形图

python - 从大数据框中选择特定行

python - 为什么参数的数量与分类变量的数量不同?

python - 使用 WingIDE 调试 Python bottle 应用程序