1
$\begingroup$

My dataset is time series data. It contains data of 10 packages. trainX = (1410,3,15), trainY= (1410,1), testX=(110,3,15), testY=(110,1). Input is three feature vectors of last three months and i am trying to predict vulnerability of 4th month. one month feature vector has 15 features. I have implemented statefull LSTM. I am training in batches by putting data of one package in one batch.

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()   

Isuess: 1. when i am trying to plot the history['loss'] and history['val_loss'],it is plotting nothing. When i am printing both then it is showing only one value. How can i plot all the training and testing loss values? 2. How can i print and calculate the values for future in time of unseen data after train,test and predict. Like what wil be the value of vulnerability in for this package in next 6 months or 9 months. How to write that function. Can somebody do this magic for me. I wil be really thankful.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.