我的数据集是时间序列数据。它包含10个数据包的数据。
trainX =(1410,3,15),trainY =(1410,1),testX =(110,3,15),testY =(110,1)
输入的内容是最近三个月的三个特征向量,我正在尝试预测第四个月的脆弱性。一个月的特征向量具有15个特征。我已经实现了有状态的LSTM。我正在将一批包装的数据放在一批中进行分批培训。
n_batch=141
# create and fit the LSTM network
model = Sequential()
model.add(LSTM(45, batch_input_shape=(n_batch, 3,15), stateful=True,
return_sequences=True))
model.add(LSTM(45, batch_input_shape=(n_batch, 3,15), stateful=True,
return_sequences=True))
model.add(LSTM(45, batch_input_shape=(n_batch, 3,15),stateful=True))
model.add(Dense(1, activation="relu"))
rmsprop = opt.RMSprop(lr=0.001)
model.compile(loss="mse", optimizer= rmsprop,metrics=['mse'])
model.summary()
for i in range(1500):
history=model.fit(trainX12, trainY12, epochs=1,
batch_size=n_batch,validation_split=0.1,verbose=2, shuffle=False)
model.reset_states()
#creating new model for test data
n_batch=11
new_model = Sequential()
new_model.add(LSTM(45, batch_input_shape=(n_batch, 3, 15), stateful=True,
return_sequences=True))
new_model.add(LSTM(45, batch_input_shape=(n_batch, 3, 15), stateful=True,
return_sequences=True))
new_model.add(LSTM(45, batch_input_shape=(n_batch, 3, 15),stateful=True))
new_model.add(Dense(1, activation="relu"))
rmsprop = opt.RMSprop(lr=0.001)
new_model.compile(loss="mse", optimizer= rmsprop)
new_model.summary()
#setting weights
old_weights = model.get_weights()
new_model.set_weights(old_weights)
#predicting from the predictions themselves (gets the training data as input
to set states)
new_model.reset_states()
#Prediction
testPredict= new_model.predict(testX12,batch_size=n_batch)
#printing history keys
print(history.history.keys())
#training and test loss
print(history.history['loss'])
history.history['val_loss']
plt.plot(history.history['loss'])
plt.plot(history.history['val_loss'])
plt.title('model loss')
plt.ylabel('loss')
plt.xlabel('epoch')
plt.legend(['train', 'test'], loc='upper left')
plt.show()
问题:
当我尝试绘制history['loss']
和history['val_loss']
时,它没有绘制任何内容。当我同时打印两者时,它仅显示一个值。如何绘制所有训练和测试损失值?
在训练,测试和预测后,如何在看不见的数据中打印和计算将来的值。就像在接下来的6个月或9个月内,此软件包中漏洞的价值是多少。如何编写该函数?有人可以帮我做这个魔术吗?