history = model.fit( { 'tempInput': xtrain[0], 'humdInput': xtrain[1], 'presInput': xtrain[2] }, {'out': ytrain}, validation_split=0.2, epochs=300, batch_size=400, verbose=2, callbacks=[checkpoint, earlystop, board]) return history x, y = getXY('./data/raw.csv', features=['Temperature', 'Td dew point', 'StnPres']) xtrain, xtest, ytrain, ytest = train_test_split(x, y, test_size=0.25) print(xtrain.shape, ytrain.shape, xtest.shape, ytest.shape) xtrainin = [ xtrain[:, :, 0][:, :, np.newaxis], xtrain[:, :, 1][:, :, np.newaxis], xtrain[:, :, 2][:, :, np.newaxis] ] xtestin = [ xtest[:, :, 0][:, :, np.newaxis], xtest[:, :, 1][:, :, np.newaxis], xtest[:, :, 2][:, :, np.newaxis] ] print('xtrain after sep feature: ', xtrainin[0].shape, xtrainin[1].shape, xtrainin[2].shape) hist = CNNsepFeature(xtrainin, ytrain) # start training
#callbacks checkpoint = ModelCheckpoint('./models/LSTMmodel.hdf5', monitor='val_loss', save_best_only=True, verbose=1) earlystop = EarlyStopping(monitor='val_loss', patience=10) board = TensorBoard(log_dir='./logs') model.compile(loss='mse', optimizer='adam') model.fit(xtrain, ytrain, epochs=300, batch_size=256, verbose=2, validation_split=0.2, callbacks=[checkpoint, earlystop]) return model x, y = getXY('./data/raw.csv') xtrain, xtest, ytrain, ytest = train_test_split(x, y, test_size=0.25) print(xtrain.shape, ytrain.shape, xtest.shape, ytest.shape) hist = LSTMmodel(xtrain, ytrain) # start training m = load_model('./models/LSTMmodel.hdf5') # load best model ypred = m.predict(xtest) print('mae: ', mae(ytest, ypred))