python - Python机器学习LSTM:无法重塑LSTM的输入
问题描述
我正在努力使 LSTM 工作。我在 Stack Overflow 上发现了一个问题:
这似乎对我有帮助,但实际上我遇到了另一个问题:无法重塑数据,但我会按照“指令”执行所有步骤。
我有 48 行 × 22 列的数据集,其中第一列是日期。标签列与该数据集分离。所以我有 21 个预测特征。
但是当我这样做时
# Extract your training data
X_train_init = np.asarray(DF.padded_input_vectors)
print(X_train_init.shape)
# Use hstack to and reshape to make the inputs a 3d vector
X_train = np.hstack(X_train_init).reshape(len(DF),max_sequence_length,21)
y_train = np.hstack(np.asarray(train_target)).reshape(len(DF),1)
我得到:
(48,)
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-14-ea37bd9226df> in <module>
3 print(X_train_init.shape)
4 # Use hstack to and reshape to make the inputs a 3d vector
----> 5 X_train = np.hstack(X_train_init).reshape(len(DF),max_sequence_length,21)
6 y_train = np.hstack(np.asarray(train_target)).reshape(len(DF),1)
ValueError: cannot reshape array of size 48 into shape (48,48,21)
解决方案
的形状(48,)
是大小为 48 的单个数组。对于 的形状(48, 48, 21)
,您需要 48,384 个元素,因此您不能将 48 个元素的大小调整为该形状。也许您需要以某种方式添加元素?无论如何,这就是重塑失败的原因。
编辑:检查您的导入,这似乎是问题所在。
推荐阅读
- reactjs - 反应路由器和上下文
- kubernetes - 我自己的 kubernetes 运行不会从官方文档中产生相同的结果
- javascript - 带有图像的jquery模态窗口
- tensorflow - 使用 tensorflow 的 OD API 时评估结果低
- laravel - 从 Laravel 阅读 gmail
- game-physics - 需要在这个马里奥游戏物理备忘单上解释
- c - 将 C 代码映射到现有的单元测试代码
- android - 如何在android中为GTM V5初始化customtagprovider及其回调方法
- sql - 在 MVC 中将大量记录从视图传递到数据库
- reactjs - 如何在打字稿中实现 else 部分?