我正在解决一个预测问题,在这个问题中,我需要根据多篇文章在过去7天的表现来预测需求。为了充分利用这些数据,我尝试实现滚动窗口方法,使用7天作为培训输入(x),使用第8天的性能作为培训标签(y)。
由于我正在使用Keras作为一个深度学习框架,如何将这种滚动窗口方法与自定义数据生成器(在培训期间为我的网络提供信息)结合起来呢?不同的条款有不同的数据长度(即A条有200天的数据,B条只有10天的数据)。
我实现了一个版本,在这个版本中,我每一篇文章只使用一个样本,但这大大减少了我培训的数据量。
发布于 2020-10-09 16:08:00
我遇到了类似的问题,我想出的快速解决方案是迭代主数据集,为每个子集创建一个TimeseriesGenerator
实例,并将其提供给模型。因此,在您的情况下,这将是:遍历文章集合,为每一篇文章实例化TimeseriesGenerator
并将窗口样例提供给您的模型,即:
from keras.preprocessing.sequence import TimeseriesGenerator
# Set the training parameters
window_length = ...
ix0, ix1 = ...
batch_size = ...
for article in articles:
# Insert your code to generate the article's features and targets
x, y = ...
model.fit_generator(TimeseriesGenerator(
x,
y,
window_length,
batch_size=batch_size,
start_index=ix0,
end_index=ix1
),
steps_per_epoch=int(np.ceil((x.shape[0] - ix0 - ix1 - window_length)/float(batch_size))),
epochs=50,
verbose=1
)
现在,根据您的数据集大小和组合,您可以:
https://datascience.stackexchange.com/questions/67637
复制相似问题