我是深度学习的初学者。谁能帮助我为什么在我想通过重塑 X 和 Y 大小对数据运行 RNN 时出现此错误

问题描述 投票:0回答:1

下面是我的代码

import numpy as np

# Check the shape of your data
print(X_train.shape)  # should be (num_samples, num_timesteps, num_features)
print(Y_train.shape)  # should be (num_samples, num_outputs)

# Convert DataFrame to numpy array
X_train = np.array(X_train)
X_val = np.array(X_val)
Y_train = np.array(Y_train)
Y_val = np.array(Y_val)


num_timesteps = 15634
num_timesteps_val = 15634
num_features = 1
X_train = X_train.reshape(-1, num_timesteps, num_features)
X_val = X_val.reshape(-1, num_timesteps_val, num_features)

# Verify the shapes of input data
print(X_train.shape)
print(X_val.shape)

# Continue with model training
history = model.fit(X_train, Y_train, epochs=100, batch_size=4, validation_data=(X_val, Y_val), callbacks=[checkpoint, early_stop])

这是我的错误信息

  (34, 15634, 1)
(15634,)
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
~\AppData\Local\Temp\ipykernel_12036\1296316449.py in <module>
     40 num_features = 1
     41 X_train = X_train.reshape(-1, num_timesteps, num_features)
---> 42 X_val = X_val.reshape(-1, num_timesteps_val, num_features)
     43 
     44 # Verify the shapes of input data

ValueError: cannot reshape array of size 59092 into shape (15634,1)

我正在尝试训练我的 RNN 模型并对其进行测试,但在重塑它时出现错误无法将大小为 59092 的数组重塑为形状 (15634,1)。我是深度学习的新手,如果有人帮忙的话会很有帮助

python deep-learning recurrent-neural-network
1个回答
-1
投票

看起来 15634 不是 num_timesteps 而是样本数,至少这是 x 和 y 的共同数。

© www.soinside.com 2019 - 2024. All rights reserved.