如何使用多个单独的训练数据训练LSTM模型?

时间:2020-08-27 01:47:37

标签: python machine-learning keras neural-network lstm

我有1年内有100个男人卖出的商品的数据。

我希望有一个模型可以预测以后所有100个销售的商品。

这是我的代码:

model=Sequential()

y_train=sells_men_sell[1] # sells_men_sell[1] is a 1d array that contains the first sells  man's sells record

x_train=sells_men_data[1] # sells_men_sell[1] is a array that contains the first sells  man's sells record for training
#, each value in the array(sells_men_sell) contains the sells record for the past 30 days.

model.add(LSTM(50, input_shape=(x_train.shape[1], x_train.shape[2])))
model.add(Dense(1))
model.compile(loss='mean_squared_error', optimizer='adam')
model.fit(x_train, y_train, batch_size=1, epoch=1)

我知道预测一个模型中有100个销售人员听起来很奇怪,但是我正在为一个项目这样做。

我应该如何处理我的代码?

我应该在model.fit(x_train, y_train, batch_size=1, epoch=1)之后添加以下代码吗?

y_train1=sells_men_sell[2] # sells_men_sell[2] is a 1d array that contains the second sells  man's sells record

x_train1=sells_men_data[2] # sells_men_sell[2] is a array that contains the second sells man's sells record for training

model.add(LSTM(50, input_shape=(x_train1.shape[1], x_train1.shape[2])))
model.fit(x_train1, y_train1, batch_size=1, epoch=1)

1 个答案:

答案 0 :(得分:0)

您的模型可以具有多个输入以及多个输出。您可以使用功能性API来实现。
我已经分享了一个有关如何实现此目标的小例子。您可以根据您的用例调整示例。

代码:

SELECT EMP_NAME, MAX(count(CONTRACT_CLIENT)

FROM CONTRACT JOIN EMPLOYER ON (CONTRACT_ID = EMP_ID)

WHERE EMP_ID = CONTRACT_ID;

生成的模型如下。

My model