【问题标题】:Get the actually used targets, not the input ones, from the TimeseriesGenerator in keras从 keras 中的 TimeseriesGenerator 获取实际使用的目标,而不是输入的目标
【发布时间】:2021-01-07 15:15:45
【问题描述】:

假设我使用 keras 创建了以下时间序列生成器:

from tensorflow.keras.preprocessing.sequence import TimeseriesGenerator
gen = TimeseriesGenerator(data=[1,2,3,4,5,6,7,8,9], targets=[1,2,3,4,5,6,7,8,9], length=2, batch_size=1, start_index=5)

由于它具有设置start_index=5,它将跳过前5个数据点,因此gen仅包含这些实际可用的数据:

# first are the data points [x_n, x_m] and then is the corresponding label/target [y_n]
print(gen[0])
print(gen[1])
>> (array([[6, 7]]), array([8]))
>> (array([[7, 8]]), array([9]))

我想要的是一种简单的方法来提取所有实际可用的目标/标签/基本事实,例如

print(gen.actual_targets)
>> [8,9]

但我最接近的是

print(gen.targets)
>> [1, 2, 3, 4, 5, 6, 7, 8, 9]

它只给出输入目标,而不是真正使用的目标。那么,我怎样才能从生成器中取出实际可用的目标呢?谢谢

【问题讨论】:

  • 如果你的原始目标是一个列表/数组... 目标[(length+start_index):]

标签: python tensorflow keras data-preprocessing


【解决方案1】:

也许你可以使用TimeseriesGenerator.start_indexTimeseriesGenerator.end_index

gen.targets[gen.start_index:gen.end_index + 1]
[8, 9]

【讨论】:

  • 谢谢,这行得通!这个问题可能没有更简单的解决方案......
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-12-11
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-04-06
  • 1970-01-01
相关资源
最近更新 更多