@@ -0,0 +1,2236 @@
+import argparse%0Aimport numpy as np%0Aimport os.path%0Afrom keras.models import Sequential%0Afrom keras.layers import LSTM, Dense%0Afrom keras.callbacks import ModelCheckpoint%0Afrom sklearn.preprocessing import StandardScaler%0A%0A%0Adef baseline_model(batch_size, timesteps, data_dim, weight_file=''):%0A    m = Sequential()%0A    m.add(LSTM(30, input_shape=(timesteps, data_dim), return_sequences=False))  # consume_less='gpu'%0A    # m.add(LSTM(30, return_sequences=False))%0A    # m.add(LSTM(30, return_sequences=False))%0A    m.add(Dense(data_dim, input_dim=30))%0A%0A    if os.path.isfile(weight_file):%0A        print('loading weights')%0A        model.load_weights(weight_file)%0A%0A    m.compile(loss='mse', optimizer='adam')%0A    return m%0A%0Adef load_data(X, Y, time_length, step):%0A    total_size = X.shape%5B0%5D%0A    if total_size != Y.shape%5B0%5D:%0A        print('X and Y do not have the same dimension')%0A        return%0A    max_samples = total_size//step + 1%0A    X_fmt = np.zeros((max_samples, time_length, X.shape%5B1%5D), dtype=%22float%22)%0A    Y_fmt = np.zeros((max_samples, Y.shape%5B1%5D), dtype=%22float%22)%0A    actual_size=0%0A    for k in range(0, total_size, step):%0A        timestep_end = k + time_length%0A        if timestep_end + 1 %3C total_size:%0A            X_fmt%5Bactual_size%5D = X%5Bk:timestep_end, :%5D%0A            Y_fmt%5Bactual_size%5D = Y%5Btimestep_end + 1%5D%0A            actual_size += 1%0A    X_fmt = X_fmt%5B:actual_size%5D%0A    Y_fmt = Y_fmt%5B:actual_size%5D%0A    return X_fmt, Y_fmt%0A%0Aap = argparse.ArgumentParser()%0Aap.add_argument(%22-t%22, %22--training%22, required=True, help=%22Path to the training data file%22)%0Aap.add_argument(%22-o%22, %22--output%22, required=True, help=%22Path to the prediction file%22)%0Aargs = vars(ap.parse_args())%0A%0Aprint('loading training data...')%0Atrain_dataset = np.loadtxt(args%5B'training'%5D, delimiter=',')%0AX, Y = load_data(train_dataset, train_dataset, time_length=40, step=10)%0Aprint(X.shape)%0Aprint(Y.shape)%0A%0Aprint('building RNN')%0Abatch_size = 50%0Acheckpoint = ModelCheckpoint(%22rnn.hdf5%22, verbose=1, save_best_only=True, monitor='val_loss')%0Acallbacks_list = %5Bcheckpoint%5D%0Amodel = baseline_model(batch_size=batch_size, timesteps=X.shape%5B0%5D, data_dim=X.shape%5B2%5D)%0A%0Aprint('training RNN')%0Amodel.fit(x=X, y=Y, validation_split=0.2, nb_epoch=10, batch_size=batch_size, callbacks=callbacks_list)%0A

Create weather.py