【发布时间】:2020-05-17 07:40:15
【问题描述】:
我的训练数据集是针对一个用户的
let training = [
[[2019.1], [10]],
[[2019.2], [2]],
[[2019.4], [11]],
[[2019.5], [31]]
]
对于这个简单的输入,我想获得下个月的预测。首先要了解 LSTM 时间序列。使用以下代码生成训练模型
let train_x = training.map(i => {return i[0]})
let train_y = training.map(j=> {return j[1]})
const model = tf.sequential();
**model.add(tf.layers.lstm({units: 128, returnSequences: false, inputShape:[train_x.length]}));**
model.add(tf.layers.dropout(0.2))
model.add(tf.layers.dense({units: training.length, activation: 'softmax'}));
model.compile({loss: 'categoricalCrossentropy', optimizer: tf.train.rmsprop(0.002)});
**const xs = tf.tensor3d([train_x]);**
const ys = tf.tensor2d(train_y, [training.length, train_y[0].length]);
错误:
Error: Input 0 is incompatible with layer lstm_LSTM1: expected ndim=3, found ndim=2
问题是应该给定什么输入形状,什么应该是 tf.tensor3d 输入。据我了解,我正在尝试这个简单的例子。在没有 keras 的情况下尝试一下
【问题讨论】:
-
因为我只有一个用户的这么多数据。我想预测下个月的数字示例 --> [[2019.6], [22]]
标签: tensorflow deep-learning model lstm tensorflow.js