用於生成批量時態數據的實用程序類。
繼承自:Sequence
用法
tf.keras.preprocessing.sequence.TimeseriesGenerator(
data, targets, length, sampling_rate=1, stride=1, start_index=0, end_index=None,
shuffle=False, reverse=False, batch_size=128
)
此類接收以相等間隔收集的 data-points 序列以及時間序列參數(例如步幅、曆史長度等),以生成用於訓練/驗證的批次。參數: data:包含連續數據點(時間步長)的可索引生成器(例如列表或 Numpy 數組)。數據應該是二維的,軸 0 應該是時間維度。目標:與 data
中的時間步相對應的目標。它的長度應與 data
相同。長度:輸出序列的長度(時間步數)。 sampling_rate:序列中連續單個時間步長之間的時間段。對於速率 r
,時間步長 data[i]
, data[i-r]
,... data[i - length]
用於創建樣本序列。步幅:連續輸出序列之間的周期。對於步幅 s
,連續輸出樣本將以 data[i]
, data[i+s]
, data[i+2*s]
等為中心。start_index:早於 start_index
的數據點將不會在輸出序列中使用。這對於保留部分數據用於測試或驗證很有用。 end_index:晚於end_index
的數據點將不會用於輸出序列。這對於保留部分數據用於測試或驗證很有用。 shuffle:是否Shuffle[洗牌]輸出樣本,或者按時間順序繪製它們。 reverse:Boolean:if true
,每個輸出樣本中的時間步長將按時間倒序排列。 batch_size:每批中的時間序列樣本數(可能最後一個除外)。返回:一個序列實例。例子:
from keras.preprocessing.sequence import TimeseriesGenerator
import numpy as np
data = np.array([[i] for i in range(50)])
targets = np.array([[i] for i in range(50)])
data_gen = TimeseriesGenerator(data, targets,
length=10, sampling_rate=2,
batch_size=2)
assert len(data_gen) == 20
batch_0 = data_gen[0]
x, y = batch_0
assert np.array_equal(x,
np.array([[[0], [2], [4], [6], [8]],
[[1], [3], [5], [7], [9]]]))
assert np.array_equal(y,
np.array([[10], [11]]))
相關用法
- Python tf.keras.preprocessing.sequence.pad_sequences用法及代碼示例
- Python tf.keras.preprocessing.sequence.make_sampling_table用法及代碼示例
- Python tf.keras.preprocessing.image.ImageDataGenerator用法及代碼示例
- Python tf.keras.preprocessing.image.smart_resize用法及代碼示例
- Python tf.keras.preprocessing.image.DirectoryIterator.__len__用法及代碼示例
- Python tf.keras.preprocessing.text.text_to_word_sequence用法及代碼示例
- Python tf.keras.applications.inception_resnet_v2.preprocess_input用法及代碼示例
- Python tf.keras.metrics.Mean.merge_state用法及代碼示例
- Python tf.keras.layers.InputLayer用法及代碼示例
- Python tf.keras.callbacks.ReduceLROnPlateau用法及代碼示例
- Python tf.keras.layers.serialize用法及代碼示例
- Python tf.keras.metrics.Hinge用法及代碼示例
- Python tf.keras.experimental.WideDeepModel.compute_loss用法及代碼示例
- Python tf.keras.metrics.SparseCategoricalAccuracy.merge_state用法及代碼示例
- Python tf.keras.metrics.RootMeanSquaredError用法及代碼示例
- Python tf.keras.applications.resnet50.preprocess_input用法及代碼示例
- Python tf.keras.metrics.SparseCategoricalCrossentropy.merge_state用法及代碼示例
- Python tf.keras.metrics.sparse_categorical_accuracy用法及代碼示例
- Python tf.keras.layers.Dropout用法及代碼示例
- Python tf.keras.activations.softplus用法及代碼示例
注:本文由純淨天空篩選整理自tensorflow.org大神的英文原創作品 tf.keras.preprocessing.sequence.TimeseriesGenerator。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。