如何使用LSTM来预测过去和现在的特征?

时间:2022-01-15 13:58:05

Suppose I have a data frame like the following, Discount is calculated from selling price/list price, unit_sales is the number of items sold on that day.

假设我有如下数据框,折扣是根据销售价格/清单价格计算的,unit_sales是当天销售的商品数量。

如何使用LSTM来预测过去和现在的特征?

If I am going to use LSTM to make sales prediction for the next day (data in the green box), based on the past 3 days of sales and discount (data frame in the red box), plus the discount to be applied on the next day (data frame in the purple box), how should I reshape the dataframe? 如何使用LSTM来预测过去和现在的特征?

如果我打算使用LSTM进行第二天的销售预测(绿色框中的数据),基于过去3天的销售和折扣(红色框中的数据框),加上要应用于第二天(紫色框中的数据框),我应该如何重塑数据帧?

This could be really easy if I don't have to consider about the discount at the current or future time step, I would just reshape it to (# of samples - 3, 3, 2)

如果我不必考虑当前或未来时间段的折扣,这可能非常简单,我只需将其重塑为(样本数量为3,3,2)

1 个解决方案

#1


0  

I would do it this way - instead of having one input into your model you can have 2: discount/sales pairs for the past 3 days with the shape (# of samples -3, 3, 2) as you suggested and another one with the shape (1,) which corresponds to the current discount. You can run the previous 3 days through the LSTM and concatenate the current discount to the output of LSTM. Using functional API it will look like this:

我会这样做 - 不是在你的模型中有一个输入,你可以有2个:过去3天的折扣/销售对,形状(样本数为3,3,2)和你建议的另一个形状(1,),对应当前折扣。您可以通过LSTM运行前3天,并将当前折扣连接到LSTM的输出。使用功能API它将如下所示:

inp_past=Input((3,2))
lstm=LSTM(32)(inp_past)
inp_now=Input((1,))
concatenation= concatenate([inp_now,lstm])
output=Dense(1)(concatenation

Does this help you a little bit?

这对你有所帮助吗?

#1


0  

I would do it this way - instead of having one input into your model you can have 2: discount/sales pairs for the past 3 days with the shape (# of samples -3, 3, 2) as you suggested and another one with the shape (1,) which corresponds to the current discount. You can run the previous 3 days through the LSTM and concatenate the current discount to the output of LSTM. Using functional API it will look like this:

我会这样做 - 不是在你的模型中有一个输入,你可以有2个:过去3天的折扣/销售对,形状(样本数为3,3,2)和你建议的另一个形状(1,),对应当前折扣。您可以通过LSTM运行前3天,并将当前折扣连接到LSTM的输出。使用功能API它将如下所示:

inp_past=Input((3,2))
lstm=LSTM(32)(inp_past)
inp_now=Input((1,))
concatenation= concatenate([inp_now,lstm])
output=Dense(1)(concatenation

Does this help you a little bit?

这对你有所帮助吗?