我想構建普通的 DNN 模型,我有 X_train= 8000000x7 和 y_train=8000000x2 的大量資料。如何創建具有 100 個資料點的滑動視窗的資料集來為神經網路提供資料。
如果我使用以下代碼使用自定義資料集,由于資料集很大,我會遇到分配問題。
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
因此,為了避免這種情況,我可以將任何資料集生成器與滑動視窗一起使用以饋入 DNN。
提前致謝
uj5u.com熱心網友回復:
您可以使用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)
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/535079.html
