多元 LSTM 输入形状
multivariant LSTM input shape
我正在尝试构建具有多个变量的 LSTM 模型。我有一个形状为 (1132, 5) 的训练数据,包括标签。所以,我有 4 个特征。我的问题是如何重塑数据,使其包含我在训练和测试数据上的特征。我做了以下代码
end_len = len(train_scaled)
X_train = []
y_train = []
timesteps = 40
for i in range(timesteps, end_len):
X_train.append(train_scaled[i - timesteps:i, 0])
y_train.append(train_scaled[i, 0])
X_train, y_train = np.array(X_train), np.array(y_train)
#train_scaled is the normalized data and it has shape of (1132, 5)
完成上述代码后,我的 X_train 变成了 (1092, 40) 它是如何从 1132 变成 1092 的?
此外,我这样做是为了使其与 Keras 兼容
# reshape data so Keras can take it namely [samples, timesteps, features].
X_train = np.reshape(X_train, (X_train.shape[0], X_train.shape[1], 1))
print("X_train --> ", X_train.shape)
print("y_train shape --> ", y_train.shape)
我的 X_train 是 (1092, 40, 1)
它没有计算我的功能,因为我最后只看到一个。
如果你的 train_scaled 的形状是 (1132, 5) ,那么你可以拆分它:
features = train_scaled[ : , 0:4]
labels = train_scaled[ : , 4:5]
我正在尝试构建具有多个变量的 LSTM 模型。我有一个形状为 (1132, 5) 的训练数据,包括标签。所以,我有 4 个特征。我的问题是如何重塑数据,使其包含我在训练和测试数据上的特征。我做了以下代码
end_len = len(train_scaled)
X_train = []
y_train = []
timesteps = 40
for i in range(timesteps, end_len):
X_train.append(train_scaled[i - timesteps:i, 0])
y_train.append(train_scaled[i, 0])
X_train, y_train = np.array(X_train), np.array(y_train)
#train_scaled is the normalized data and it has shape of (1132, 5)
完成上述代码后,我的 X_train 变成了 (1092, 40) 它是如何从 1132 变成 1092 的?
此外,我这样做是为了使其与 Keras 兼容
# reshape data so Keras can take it namely [samples, timesteps, features].
X_train = np.reshape(X_train, (X_train.shape[0], X_train.shape[1], 1))
print("X_train --> ", X_train.shape)
print("y_train shape --> ", y_train.shape)
我的 X_train 是 (1092, 40, 1)
它没有计算我的功能,因为我最后只看到一个。
如果你的 train_scaled 的形状是 (1132, 5) ,那么你可以拆分它:
features = train_scaled[ : , 0:4]
labels = train_scaled[ : , 4:5]