从 keras

问题描述

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

from tensorflow.keras.preprocessing.sequence import TimeseriesGenerator
gen = TimeseriesGenerator(data=[1,2,3,4,5,6,7,8,9],targets=[1,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,9]

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

解决方法

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

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

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...