首页 > 解决方案 > TF 2.0 LSTM:如何用于支出预测?

问题描述

我想使用 TensorFlow 2.0 中的 LSTM 来预测下个月的所有客户支出(这可能不是常见的 LSTM 用例)。我的数据有 10k 个客户每月的支出数据。

格式:

Customer ID,  time(yyyymm), target(spending), age, gender,  all other features.....
customer 1,   201912,       100
customer 1,   201911,       200
...
customer 1,   201402,       300
customer 1,   201401,       100
customer 2,   201912,        0
....
customer 2,   201401,       50
customer 3,   201912,       100
....
customer 10k, 201401

它有 4 个维度用于 LSTM 的输入:(10k customers * 60 months samples * 3 timesteps (quarterly) * 100 features). 通常 LSTM 需要 3 个维度:(nb_samples, timesteps, features)

我的问题:

我想我仍然不确定我的数据的正确方法是什么。我把我的起始代码放在下面,但我认为我的一些低估是不正确的:

lstm_input = tf.keras.layers.Input(shape=(60,3,100), name='lstm_input') 
x = tf.keras.layers.LSTM(64, name='lstm_0',return_sequences=True)(lstm_input)
x = tf.keras.layers.GlobalMaxPooling1D()(x)
....

我应该改变什么以使我的数据适合 LSTM 或 RNN 模型?

更新

我想我可能需要像下面这样输入?还是我什至应该使用 RNN/LSTM 对其进行建模?

  [         Month1                    Month2                  ...  Month60
customer 1: [[fe1(1,1)...fe100(1,1)], [fe1(1,2)...fe100(1,2)],... ,[fe1(1,60)...fe100(1,60)]]
customer 2: [[fe1(2,1)...fe100(2,1)], [fe1(2,2)...fe100(2,2)],... ,[fe1(2,60)...fe100(2,60)]]
  ....
customer N: [[fe1(n,1)...fe100(n,1)], [fe1(n,2)...fe100(n,2)],... ,[fe1(n,60)...fe100(n,60)]]
  ]

标签: pythontensorflowkeraslstm

解决方案


也许这个观察有帮助。为每个客户获取每个月的总支出。这样,您就有了固定数量的时间步长(60 个月)和 10k 个样本。我假设你知道这里解释的所有术语。

我也不明白 *3(季度)部分,数据是在三个月内采样的吗?


推荐阅读