【问题标题】:TF 2.0 LSTM: How to use for a Spending prediction?TF 2.0 LSTM:如何用于支出预测?
【发布时间】:2020-10-21 18:18:48
【问题描述】:

我想使用 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

LSTM 的输入有 4 个维度:(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)]]
  ]

【问题讨论】:

    标签: python tensorflow keras lstm


    【解决方案1】:

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

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

    【讨论】:

    • 好吧,我想我最初的想法是不正确的。我最初将 *3(每季度)视为时间步长。现在我觉得我应该删除它并将最终输入数组设为 3d(10k,60 个月,100 个特征)并将其输入 LSTM。我不知道这是否是一个好习惯?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-08-25
    • 2020-04-08
    • 1970-01-01
    • 2021-06-30
    • 1970-01-01
    • 2019-02-19
    • 2020-08-24
    相关资源
    最近更新 更多