<jupyter_start><jupyter_text>Model training<jupyter_code>del model
batch_size = 1
model = Sequential()
model.add(GRU(1, batch_input_shape=(batch_size, train_x.shape[1], train_x.shape[2]), return_sequences=True))
model.add(GRU(1))
model.add(Dense(train_y.shape[1]))

model.compile(loss='mean_squared_error', optimizer='sgd')
es = EarlyStopping(monitor='val_loss',
                              min_delta=0,
                              patience=3,
                              verbose=0, mode='auto')
history = model.fit(train_x, train_y, epochs=20, batch_size=batch_size, verbose=1, validation_data=(val_x, val_y), shuffle=True, callbacks=[es])

# fit network
early_stopping_counter = 0
last_loss = np.inf
for i in range(10):
    history = model.fit(train_x, train_y, epochs=1, batch_size=batch_size, verbose=1, validation_data=(val_x, val_y), shuffle=True)
    model.reset_states()
    val_loss = history.history['val_loss'][0]
    if val_loss > last_loss:
        early_stopping_counter += 1
    else:    
        early_stopping_counter = 0
    last_loss = val_loss
    if early_stopping_counter == 3:
#         break
        pass<jupyter_output>Train on 11270 samples, validate on 2842 samples
Epoch 1/1
11270/11270 [==============================] - 55s 5ms/step - loss: 0.0308 - val_loss: 0.0195
Train on 11270 samples, validate on 2842 samples
Epoch 1/1
11270/11270 [==============================] - 55s 5ms/step - loss: 0.0284 - val_loss: 0.0199
Train on 11270 samples, validate on 2842 samples
Epoch 1/1
11270/11270 [==============================] - 52s 5ms/step - loss: 0.0270 - val_loss: 0.0221
Train on 11270 samples, validate on 2842 samples
Epoch 1/1
11270/11270 [==============================] - 55s 5ms/step - loss: 0.0263 - val_loss: 0.0201
Train on 11270 samples, validate on 2842 samples
Epoch 1/1
11270/11270 [==============================] - 50s 4ms/step - loss: 0.0259 - val_loss: 0.0202
Train on 11270 samples, validate on 2842 samples
Epoch 1/1
11270/11270 [==============================] - 51s 5ms/step - loss: 0.0259 - val_loss: 0.0202
Train on 11270 samples, validate on 2842 samples
Epoch 1/1
11270/11270 [==========[...]<jupyter_text>Prediction<jupyter_code>val_y_pred = model.predict(val_x, batch_size=batch_size, verbose=1)
inverted_val_y = scaler.inverse_transform(val_y)
inverted_val_y_pred = scaler.inverse_transform(val_y_pred)
Y = model.predict(X, batch_size=batch_size)  # predict for today's values
inv_Y = scaler.inverse_transform(Y)  # invert to detrended values' scale
rescaled_Y = [x+y for x, y in zip(inv_Y[:, 0], df.iloc[:, -1])]  # last day's values added to inv_Y to get it to original scale

val_RMSE = np.sqrt(np.sum(np.square(np.array(inverted_val_y_pred) - np.array(inverted_val_y))) / len(inverted_val_y)) 
RMSE = np.sqrt(np.sum(np.square(np.array(rescaled_Y) - load)) / len(load)) 
print(val_RMSE, RMSE)
plt.plot(load)
plt.plot(rescaled_Y)
plt.legend(['load', 'pred'])


# !jupyter nbconvert --to script LSTM-v2.ipynb
# ## get today's load

# def get_load_data(date):
#     load=[]
#     url = 'http://www.delhisldc.org/Loaddata.aspx?mode='
#     print('Scraping ' + date, end=' ')
#     resp = requests.get(url + date) # send a get request to the url, get response
#     soup = BeautifulSoup(resp.text, 'lxml') # Yummy HTML soup
#     table = soup.find('table', {'id':'ContentPlaceHolder3_DGGridAv'}) # get the table from html
#     trs = table.findAll('tr') # extract all rows of the table
#     if len(trs[1:])==288: # no need to create csv file, if there's no data
#         with open('monthdata.csv', 'a') as f:  #'a' makes sure the values are appended at the end of the already existing file
            
#             for tr in trs[1:]:
#                 time, delhi = tr.findChildren('font')[:2]
#                 load.append(delhi.text)
#     if len(trs[1:]) != 288:
#         print('Some of the load values are missing..')
#     else:
#         print('Done')
#     return load

# yesterday = datetime.today() - timedelta(1)
# yesterday = yesterday.strftime('%d/%m/%Y')
# load = get_load_data(yesterday)
# load = [float(x) for x in load]
# np.save('25nov.npy', load)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.17295219793418207, 'fraction_numerical': 0.0634158059092001, 'mean_word_length': 3.808314087759815, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 1, 'xml': 1}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '73643', 'license': 'MIT', 'n_tokens_mistral': 1677, 'n_tokens_neox': 1458, 'n_words': 358, 'path': 'models/GRU.ipynb', 'repo_name': 'rishabhiitbhu/btech_project', 'size': '4163'}