import argparse
import numpy as np
import os.path
from keras.models import Sequential
from keras.layers import LSTM, Dense
from keras.callbacks import ModelCheckpoint
from sklearn.preprocessing import StandardScaler


def baseline_model(batch_size, timesteps, data_dim, weight_file=''):
    m = Sequential()
    m.add(LSTM(30, input_shape=(timesteps, data_dim), return_sequences=False))  # consume_less='gpu'
    # m.add(LSTM(30, return_sequences=False))
    # m.add(LSTM(30, return_sequences=False))
    m.add(Dense(data_dim, input_dim=30))

    if os.path.isfile(weight_file):
        print('loading weights')
        model.load_weights(weight_file)

    m.compile(loss='mse', optimizer='adam')
    return m

def load_data(X, Y, time_length, step):
    total_size = X.shape[0]
    if total_size != Y.shape[0]:
        print('X and Y do not have the same dimension')
        return
    max_samples = total_size//step + 1
    X_fmt = np.zeros((max_samples, time_length, X.shape[1]), dtype="float")
    Y_fmt = np.zeros((max_samples, Y.shape[1]), dtype="float")
    actual_size=0
    for k in range(0, total_size, step):
        timestep_end = k + time_length
        if timestep_end + 1 < total_size:
            X_fmt[actual_size] = X[k:timestep_end, :]
            Y_fmt[actual_size] = Y[timestep_end + 1]
            actual_size += 1
    X_fmt = X_fmt[:actual_size]
    Y_fmt = Y_fmt[:actual_size]
    return X_fmt, Y_fmt

ap = argparse.ArgumentParser()
ap.add_argument("-t", "--training", required=True, help="Path to the training data file")
ap.add_argument("-o", "--output", required=True, help="Path to the prediction file")
args = vars(ap.parse_args())

print('loading training data...')
train_dataset = np.loadtxt(args['training'], delimiter=',')
X, Y = load_data(train_dataset, train_dataset, time_length=40, step=10)
print(X.shape)
print(Y.shape)

print('building RNN')
batch_size = 50
checkpoint = ModelCheckpoint("rnn.hdf5", verbose=1, save_best_only=True, monitor='val_loss')
callbacks_list = [checkpoint]
model = baseline_model(batch_size=batch_size, timesteps=X.shape[0], data_dim=X.shape[2])

print('training RNN')
model.fit(x=X, y=Y, validation_split=0.2, nb_epoch=10, batch_size=batch_size, callbacks=callbacks_list)

@@ -209,16 +209,52 @@
 dScaler%0A
+from progressbar import ProgressBar%0A
 %0A%0Adef ba
@@ -266,28 +266,16 @@
 e_model(
-batch_size, 
 timestep
@@ -638,20 +638,16 @@
        m
-odel
 .load_we
@@ -1714,21 +1714,16 @@
 ')%0Atrain
-_data
 set = np
@@ -1768,78 +1768,221 @@
 ,')%0A
-X, 
 Y = 
-load_data(train_dataset, train_dataset, time_length=40, step=10
+trainset%0A%0Aprint('scaling data')%0Ass = StandardScaler()%0Ass.fit(trainset)%0AX = ss.transform(trainset)%0A%0Aprint('reformat data')%0Atimelength = 40%0Anb_step = 3%0AX, Y = load_data(X, Y, time_length=timelength, step=nb_step
 )%0Apr
@@ -2049,10 +2049,17 @@
 e = 
-50
+30%0Adim=11
 %0Ache
@@ -2205,51 +2205,18 @@
 del(
-batch_size=batch_size, timesteps=X.shape%5B0%5D
+timelength
 , da
@@ -2226,18 +2226,11 @@
 dim=
-X.shape%5B2%5D
+dim
 )%0A%0Ap
@@ -2293,9 +2293,10 @@
 t=0.
-2
+05
 , nb
@@ -2306,10 +2306,9 @@
 och=
-10
+2
 , ba
@@ -2354,8 +2354,726 @@
 s_list)%0A
+%0Aprint('predicting data')%0Amodel = baseline_model(timelength, data_dim=dim, weight_file='rnn.hdf5')%0A%0Aprediction_timestep = 12 * 144%0Aval_prediction = np.zeros((prediction_timestep, dim), dtype='float')%0Ainput = ss.transform(trainset%5Btrainset.shape%5B0%5D - timelength : trainset.shape%5B0%5D%5D)%0A# input = X%5BX.shape%5B0%5D-1%5D%0A%0Apbar = ProgressBar(maxval=prediction_timestep).start()%0Afor t in range(prediction_timestep):%0A    output = model.predict(input)%0A    val_prediction%5Bt%5D = output%0A    input = np.roll(input, -1, axis=0)%0A    input%5Btimelength-1%5D = ss.transform(output)%0A    pbar.update(progress)%0A    progress += 1%0Apbar.finish()%0A%0Aprint('val prediction shape = %7B%7D'.format(val_prediction.shape))%0Anp.savetxt(val_prediction, delimiter=',')%0A

Update weather.py