[英]how to create a dataset for multi-output regression with sliding window approach
我想構建普通的 DNN model,我有 X_train=8000000x7 和 y_train=8000000x2 的大量數據。 如何創建一個包含 100 個數據點的滑動 window 的數據集來饋送 neural.network。
如果我使用以下代碼使用自定義數據集,由於數據集很大,我會遇到分配問題。
def data_set(x_data, y_data, num_steps=160):
X, y = list(), list()
# Loop of the entire data set
for i in range(x_data.shape[0]):
# compute a new (sliding window) index
end_ix = i + num_steps
# if index is larger than the size of the dataset, we stop
if end_ix >= x_data.shape[0]:
break
# Get a sequence of data for x
seq_X = x_data[i:end_ix]
# Get only the last element of the sequency for y
seq_y = y_data[end_ix]
# Append the list with sequencies
X.append(seq_X)
y.append(seq_y)
# Make final arrays
x_array = np.array(X)
y_array = np.array(y)
return x_array, y_array
因此,為了避免這種情況,我可以使用任何數據集生成器和滑動 window 來輸入 DNN。
提前致謝
您可以使用dataset.window
方法來實現。
dataset = tf.data.Dataset.from_tensor_slices((X_train, y_train))
stride = 1
dataset = dataset.window(batch_size, shift=batch_size-stride, drop_remainder=True)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.