【发布时间】:2019-05-08 06:14:02
【问题描述】:
我需要准备我的数据以将其输入 LSTM 以预测第二天。
我的数据集是以秒为单位的时间序列,但我每天只有 3-5 小时的数据。 (我只有这个特定的数据集所以不能改变它)
我有Date-Time 和某个Value。
例如:
datetime..............Value
2015-03-15 12:00:00...1000
2015-03-15 12:00:01....10
.
.
我想写一个我提取的代码,例如4 小时并删除特定月份的第一个提取小时(因为此数据有误)。
我设法编写了一个代码来提取例如x-Data(输入)和y-Data(输出)需要 2 小时。
我希望我能向你解释我的问题。
数据集是以秒为单位的 1 年数据,缺少下午 6 点到晚上 11 点的休息时间。 在例如8-11月第一个小时是错误数据,需要删除。
init = True
for day in np.unique(x_df.index.date):
temp = x_df.loc[(day + pd.DateOffset(hours=18)):(day + pd.DateOffset(hours=20))]
if len(temp) == 7201:
if init:
x_df1 = np.array([temp.values])
init = False
else:
#print (temp.values.shape)
x_df1 = np.append(x_df1, np.array([temp.values]), axis=0)
#else:
#if not temp.empty:
#print (temp.index[0].date(), len(temp))
x_df1 = np.array(x_df1)
print('X-Shape:', x_df1.shape,
'Y-Shape:', y_df1.shape)
#sample, timesteps and features for LSTM
X-Shape: (32, 7201, 6) Y-Shape: (32, 7201)
我的预期结果是有一个数据集,例如每天 4 小时,例如第一个小时。八月、九月和十月被删除。 如果有人也可以为我提供更好的代码,我也会很高兴。
【问题讨论】:
标签: python time-series lstm data-cleaning