This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
model_lstm.compile(loss=tf.keras.metrics.mean_squared_error, | |
metrics=[tf.keras.metrics.RootMeanSquaredError(name='rmse')], optimizer='adam') | |
early_stop = EarlyStopping(monitor='loss', patience=5, verbose=1) | |
history_model_lstm = model_lstm.fit(X_tr_t, y_train, epochs=100, batch_size=1, verbose=1, shuffle=False, callbacks=[early_stop]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from keras.layers import LSTM | |
K.clear_session() | |
model_lstm = Sequential() | |
model_lstm.add(LSTM(50, input_shape=(1, X_train.shape[1]), activation='relu', kernel_initializer='lecun_uniform', return_sequences=False)) | |
model_lstm.add(Dense(1)) | |
model_lstm.summary() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
X_tr_t = X_train.reshape(X_train.shape[0], 1, X_train.shape[1]) | |
X_tst_t = X_test.reshape(X_test.shape[0], 1, X_test.shape[1]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
model.compile(loss=tf.keras.metrics.mean_squared_error, metrics=[tf.keras.metrics.RootMeanSquaredError(name='rmse')], optimizer='adam') | |
early_stop = EarlyStopping(monitor='loss', patience=2, verbose=1) | |
history = model.fit(X_train, y_train, epochs=200, batch_size=1, verbose=1, callbacks=[early_stop], shuffle=False) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
K.clear_session() | |
model = Sequential() | |
model.add(Dense(12, input_dim=1, activation='relu')) | |
model.add(Dense(1)) | |
model.summary() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
X_train = train_sc[:-1] | |
y_train = train_sc[1:] | |
X_test = test_sc[:-1] | |
y_test = test_sc[1:] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from sklearn.preprocessing import StandardScaler | |
sc = StandardScaler() | |
train_sc = sc.fit_transform(train) | |
test_sc = sc.transform(test) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#setting the split date | |
split_date = pd.Timestamp('26-08-2018') | |
# creating training dataframe | |
train = df.loc[:split_date] | |
# creating test dataframe | |
test = df.loc[split_date:] | |
#plotting train test dataframe as aline plot | |
ax = train.plot(kind='line',figsize=(12,8)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
df = data_frame[["Price"]] | |
#plotting dataset to visualize the pattern of prices over the years | |
df.plot(kind='line',figsize=(12,7)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# sorting the dataset in ascending order of date | |
data_frame = ind_exchange_data.sort_index(axis=1 ,ascending=True) | |
data_frame = data_frame.iloc[::-1] | |
data_frame.head() |