# Last updated: 10/18/2023.
# Copyright 2023 Shane Khalid. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ==============================================================================
import math
import time
import numpy as np
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
import matplotlib.dates as mdates
import tensorflow as tf
from keras.models import Sequential
from keras.callbacks import EarlyStopping
from keras.layers import LSTM, Dense, Dropout
from datetime import date, timedelta, datetime
from pandas.plotting import register_matplotlib_converters
from sklearn.preprocessing import RobustScaler, MinMaxScaler
from sklearn.metrics import mean_absolute_error, mean_squared_error
from tensorflow.keras import utils
# Always use the GPU
print("Num GPUs Available: ", len(tf.config.experimental.list_physical_devices('GPU')))
import os
import csv
import json
import datetime
import pandas as pd
from tqdm import tqdm
import snscrape.modules.twitter as sntwitter
from datetime import datetime
Num GPUs Available: 1
# Downloading hostorical stock price data from 1st Jan 2010 to today
stockname = 'GOOG'
interval = '1d'
date_today = date.today()
date_start = datetime.strptime('2010-01-01', "%Y-%m-%d")
period1 = int(time.mktime(date_start.timetuple()))
period2 = int(time.mktime(date_today.timetuple()))
query_string = f'https://query1.finance.yahoo.com/v7/finance/download/{stockname}?period1={period1}&period2={period2}&interval={interval}&events=history&includeAdjustedClose=true'
# Saving data to CSV file
stocks_data = pd.read_csv(query_string)
stocks_data.to_csv(stockname + '.csv')
# Loading data into dataframe
df = pd.read_csv(stockname + '.csv',parse_dates = True,index_col=['Date'])
df = df.drop(['Unnamed: 0'],axis=1)
df.head()
Open | High | Low | Close | Adj Close | Volume | |
---|---|---|---|---|---|---|
Date | ||||||
2010-01-04 | 15.615220 | 15.678981 | 15.547723 | 15.610239 | 15.610239 | 78541293 |
2010-01-05 | 15.620949 | 15.637387 | 15.480475 | 15.541497 | 15.541497 | 120638494 |
2010-01-06 | 15.588072 | 15.588072 | 15.102393 | 15.149715 | 15.149715 | 159744526 |
2010-01-07 | 15.178109 | 15.193053 | 14.760922 | 14.797037 | 14.797037 | 257533695 |
2010-01-08 | 14.744733 | 15.024933 | 14.672753 | 14.994298 | 14.994298 | 189680313 |
# Plotting line charts
df_plot = df.copy()
list_length = df_plot.shape[1]
ncols = 2
nrows = int(round(list_length / ncols, 0))
fig, ax = plt.subplots(nrows=nrows, ncols=ncols, sharex=True, figsize=(14, 7))
fig.subplots_adjust(hspace=0.5, wspace=0.5)
colors = ['blue', 'red', 'green', 'pink', 'orange', 'purple']
for i in range(0, list_length):
ax = plt.subplot(nrows,ncols,i+1)
sns.lineplot(data = df_plot.iloc[:, i], ax=ax, color= colors[i])
ax.set_title(df_plot.columns[i])
ax.tick_params(axis="x", rotation=30, labelsize=10, length=0)
ax.xaxis.set_major_locator(mdates.AutoDateLocator())
fig.tight_layout()
plt.show()
# Creating n samples, sequence_length time steps per samples
def splitData(sequence_length, data, index_Close):
x, y = [], []
data_len = data.shape[0]
for i in range(sequence_length, data_len):
#contains sequence_length values 0-sequence_length * columns
x.append(data[i-sequence_length:i,:])
#contains the prediction values for validation, for single-step prediction
y.append(data[i, index_Close])
# Convert the x & y to numpy arrays
x = np.array(x)
y = np.array(y)
return x, y
def processData(df, FEATURES):
# Indexing the batches
train_df = df.sort_values(by=['Date']).copy()
# Saving a copy of the dates' index, before we need to reset it to numbers
date_index = train_df.index
# Reset the index, so we can convert the date-index to a number-index
train_df = train_df.reset_index(drop=True).copy()
# Create the dataset with features and filter the data to the list of FEATURES
data = pd.DataFrame(train_df)
data_filtered = data[FEATURES]
# Adding a prediction column (target variable) and setting dummy values to prepare the data for scaling
data_filtered_ext = data_filtered.copy()
data_filtered_ext['Prediction'] = data_filtered_ext['Close']
# Number of rows in the data
nrows = data_filtered.shape[0]
# Convert data to numpy values
np_data_unscaled = np.array(data_filtered)
np_data = np.reshape(np_data_unscaled, (nrows, -1))
# Transform the data by scaling each feature to a range between 0 and 1
scaler = MinMaxScaler()
np_data_scaled = scaler.fit_transform(np_data_unscaled)
# Creating a separate scaler that works on a single column for scaling predictions
scaler_pred = MinMaxScaler()
df_Close = pd.DataFrame(data_filtered_ext['Close'])
np_Close_scaled = scaler_pred.fit_transform(df_Close)
# sequence length: this is the timeframe used to make a single prediction
sequence_length = 50
# Prediction Index
index_Close = data.columns.get_loc("Close")
# Split the training data into train and test datasets with 80:20 split
train_data_len = math.ceil(np_data_scaled.shape[0] * 0.8)
# Creating the training and test data
train_data = np_data_scaled[0:train_data_len, :]
test_data = np_data_scaled[train_data_len - sequence_length:, :]
# Generate training data and test data
x_train, y_train = splitData(sequence_length, train_data, index_Close)
x_test, y_test = splitData(sequence_length, test_data, index_Close)
return x_train, y_train, x_test, y_test, data_filtered, \
date_index, scaler, scaler_pred, train_data_len, sequence_length
# Setting up LSTM model architecture
def getModel(x_train):
# Creating model with n_neurons = inputshape Timestamps, each with x_train.shape[2] variables
model = Sequential()
n_neurons = x_train.shape[1] * x_train.shape[2]
model.add(LSTM(n_neurons, return_sequences=True, input_shape=(x_train.shape[1], x_train.shape[2])))
model.add(LSTM(n_neurons, return_sequences=False))
model.add(Dense(5))
model.add(Dense(1))
# Compiling the model
model.compile(optimizer='adam', loss='mse')
return model
def plotLossCurve(history, color, title):
# Plot the Loss Curve
fig, ax = plt.subplots(figsize=(7, 6), sharex=True)
plt.plot(history.history["loss"],color=color)
plt.title(title)
plt.ylabel("Loss")
plt.xlabel("Epoch")
plt.xticks(rotation=45)
plt.legend(["Train", "Test"], loc="upper left")
plt.show()
def eval(model, x_test, y_test, scaler_pred):
# Get the predicted values
y_pred_scaled = model.predict(x_test)
# Unscale the predicted values
y_pred = scaler_pred.inverse_transform(y_pred_scaled)
y_test_unscaled = scaler_pred.inverse_transform(y_test.reshape(-1, 1))
# Mean Absolute Error (MAE)
MAE = mean_absolute_error(y_test_unscaled, y_pred)
print(f'Median Absolute Error (MAE): {np.round(MAE, 2)}')
# Mean Absolute Percentage Error (MAPE)
MAPE = np.mean((np.abs(np.subtract(y_test_unscaled, y_pred)/ y_test_unscaled))) * 100
print(f'Mean Absolute Percentage Error (MAPE): {np.round(MAPE, 2)} %')
# Median Absolute Percentage Error (MDAPE)
MDAPE = np.median((np.abs(np.subtract(y_test_unscaled, y_pred)/ y_test_unscaled)) ) * 100
print(f'Median Absolute Percentage Error (MDAPE): {np.round(MDAPE, 2)} %')
return MAE, MAPE, MDAPE, y_pred
def visualizePreds(data_filtered, train_data_len, y_pred, date_index, color):
# The date from which on the date is displayed
display_start_date = pd.Timestamp('today') - timedelta(days=500)
# Add the date column
data_filtered_sub = data_filtered.copy()
data_filtered_sub['Date'] = date_index
# Add the difference between the valid and predicted prices
train = data_filtered_sub[:train_data_len + 1]
valid = data_filtered_sub[train_data_len:]
valid.insert(1, "Prediction", y_pred.ravel(), True)
valid.insert(1, "Difference", valid["Prediction"] - valid["Close"], True)
# Zoom in to a closer timeframe
valid = valid[valid['Date'] > display_start_date]
train = train[train['Date'] > display_start_date]
# Visualize the data
fig, ax1 = plt.subplots(figsize=(10, 7), sharex=True)
xt = train['Date']; yt = train[["Close"]]
xv = valid['Date']; yv = valid[["Close", "Prediction"]]
plt.title("Predictions vs Actual Values", fontsize=20)
plt.ylabel(stockname, fontsize=18)
plt.plot(xt, yt, color="green", linewidth=2.0)
plt.plot(xv, yv["Prediction"], color=color, linewidth=2.0)
plt.plot(xv, yv["Close"], color="black", linewidth=2.0)
plt.legend(["Train", "Test Predictions", "Actual Values"], loc="upper left")
plt.show()
def predictFuturePrice(model, df, sequence_length, feats, scaler, scaler_pred):
df_temp = df[-sequence_length:]
new_df = df_temp.filter(feats)
N = sequence_length
# Get the last N day closing price values and scale the data to be values between 0 and 1
last_N_days = new_df[-sequence_length:].values
last_N_days_scaled = scaler.transform(last_N_days)
# Create an empty list and Append past N days
X_test_new = []
X_test_new.append(last_N_days_scaled)
# Convert the X_test data set to a numpy array and reshape the data
pred_price_scaled = model.predict(np.array(X_test_new))
pred_price_unscaled = scaler_pred.inverse_transform(pred_price_scaled.reshape(-1, 1))
# Print last price and predicted price for the next day
price_today = np.round(new_df['Close'][-1], 2)
predicted_price = np.round(pred_price_unscaled.ravel()[0], 2)
change_percent = np.round(100 - (price_today * 100)/predicted_price, 2)
plus = '+'; minus = ''
print(f'The close price for {stockname} at {date_today} was {price_today}')
print(f'The predicted close price is {predicted_price} ({plus if change_percent > 0 else minus}{change_percent}%)')
# List of considered features
features1 = ['High', 'Low', 'Open', 'Close', 'Volume']
# Split and process dataset
x_train1, y_train1, x_test1, y_test1, data_filtered1, date_index1, \
scaler1, scaler_pred1, train_data_len1, sequence_length1 = processData(df, features1)
# Get Model
model1 = getModel(x_train1)
#Visualizing Model Architecture
import tensorflow as tf
tf.keras.utils.plot_model(model1, show_shapes=True)
print("Num GPUs Available: ", len(tf.config.experimental.list_physical_devices('GPU')))
!pip3 install pydot
!pip3 install graphviz
2023-10-19 17:27:27.723503: I tensorflow/compiler/xla/stream_executor/cuda/cuda_gpu_executor.cc:880] could not open file to read NUMA node: /sys/bus/pci/devices/0000:43:00.0/numa_node Your kernel may have been built without NUMA support. 2023-10-19 17:27:27.723609: I tensorflow/compiler/xla/stream_executor/cuda/cuda_gpu_executor.cc:880] could not open file to read NUMA node: /sys/bus/pci/devices/0000:43:00.0/numa_node Your kernel may have been built without NUMA support. 2023-10-19 17:27:27.723648: I tensorflow/compiler/xla/stream_executor/cuda/cuda_gpu_executor.cc:880] could not open file to read NUMA node: /sys/bus/pci/devices/0000:43:00.0/numa_node Your kernel may have been built without NUMA support. 2023-10-19 17:27:28.951549: I tensorflow/compiler/xla/stream_executor/cuda/cuda_gpu_executor.cc:880] could not open file to read NUMA node: /sys/bus/pci/devices/0000:43:00.0/numa_node Your kernel may have been built without NUMA support. 2023-10-19 17:27:28.951619: I tensorflow/compiler/xla/stream_executor/cuda/cuda_gpu_executor.cc:880] could not open file to read NUMA node: /sys/bus/pci/devices/0000:43:00.0/numa_node Your kernel may have been built without NUMA support. 2023-10-19 17:27:28.951627: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1977] Could not identify NUMA node of platform GPU id 0, defaulting to 0. Your kernel may not have been built with NUMA support. 2023-10-19 17:27:28.951697: I tensorflow/compiler/xla/stream_executor/cuda/cuda_gpu_executor.cc:880] could not open file to read NUMA node: /sys/bus/pci/devices/0000:43:00.0/numa_node Your kernel may have been built without NUMA support. 2023-10-19 17:27:28.951724: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1886] Created device /job:localhost/replica:0/task:0/device:GPU:0 with 21080 MB memory: -> device: 0, name: NVIDIA GeForce RTX 3090 Ti, pci bus id: 0000:43:00.0, compute capability: 8.6 2023-10-19 17:31:22.443601: I tensorflow/tsl/platform/default/subprocess.cc:304] Start cannot spawn child process: No such file or directory
You must install pydot (`pip install pydot`) and install graphviz (see instructions at https://graphviz.gitlab.io/download/) for plot_model to work. Num GPUs Available: 1 Defaulting to user installation because normal site-packages is not writeable Requirement already satisfied: pydot in ./.local/lib/python3.10/site-packages (1.4.2) Requirement already satisfied: pyparsing>=2.1.4 in /usr/lib/python3/dist-packages (from pydot) (2.4.7) Defaulting to user installation because normal site-packages is not writeable Requirement already satisfied: graphviz in ./.local/lib/python3.10/site-packages (0.20.1)
model1.summary()
Model: "sequential" _________________________________________________________________ Layer (type) Output Shape Param # ================================================================= lstm (LSTM) (None, 50, 250) 256000 lstm_1 (LSTM) (None, 250) 501000 dense (Dense) (None, 5) 1255 dense_1 (Dense) (None, 1) 6 ================================================================= Total params: 758261 (2.89 MB) Trainable params: 758261 (2.89 MB) Non-trainable params: 0 (0.00 Byte) _________________________________________________________________
# Training the model
epochs = 300
history1 = model1.fit(x_train1, y_train1, batch_size=512, epochs=epochs, validation_data=(x_test1, y_test1))
Epoch 1/300 6/6 [==============================] - 0s 36ms/step - loss: 5.1939e-05 - val_loss: 5.8007e-04 Epoch 2/300 6/6 [==============================] - 0s 29ms/step - loss: 5.1459e-05 - val_loss: 6.0817e-04 Epoch 3/300 6/6 [==============================] - 0s 29ms/step - loss: 5.6616e-05 - val_loss: 5.9028e-04 Epoch 4/300 6/6 [==============================] - 0s 29ms/step - loss: 5.9010e-05 - val_loss: 8.4292e-04 Epoch 5/300 6/6 [==============================] - 0s 29ms/step - loss: 6.1818e-05 - val_loss: 5.7464e-04 Epoch 6/300 6/6 [==============================] - 0s 29ms/step - loss: 5.3029e-05 - val_loss: 5.6822e-04 Epoch 7/300 6/6 [==============================] - 0s 29ms/step - loss: 5.1655e-05 - val_loss: 5.7920e-04 Epoch 8/300 6/6 [==============================] - 0s 29ms/step - loss: 5.0274e-05 - val_loss: 5.6693e-04 Epoch 9/300 6/6 [==============================] - 0s 28ms/step - loss: 5.1249e-05 - val_loss: 5.5994e-04 Epoch 10/300 6/6 [==============================] - 0s 29ms/step - loss: 5.0582e-05 - val_loss: 5.6805e-04 Epoch 11/300 6/6 [==============================] - 0s 29ms/step - loss: 5.1368e-05 - val_loss: 5.7401e-04 Epoch 12/300 6/6 [==============================] - 0s 27ms/step - loss: 5.1662e-05 - val_loss: 5.5698e-04 Epoch 13/300 6/6 [==============================] - 0s 28ms/step - loss: 5.4154e-05 - val_loss: 5.5627e-04 Epoch 14/300 6/6 [==============================] - 0s 28ms/step - loss: 5.2049e-05 - val_loss: 6.3676e-04 Epoch 15/300 6/6 [==============================] - 0s 29ms/step - loss: 5.1783e-05 - val_loss: 5.7822e-04 Epoch 16/300 6/6 [==============================] - 0s 28ms/step - loss: 4.9757e-05 - val_loss: 5.7506e-04 Epoch 17/300 6/6 [==============================] - 0s 28ms/step - loss: 4.9588e-05 - val_loss: 5.7315e-04 Epoch 18/300 6/6 [==============================] - 0s 29ms/step - loss: 5.0603e-05 - val_loss: 5.9778e-04 Epoch 19/300 6/6 [==============================] - 0s 28ms/step - loss: 5.1515e-05 - val_loss: 5.5057e-04 Epoch 20/300 6/6 [==============================] - 0s 37ms/step - loss: 5.0911e-05 - val_loss: 5.9532e-04 Epoch 21/300 6/6 [==============================] - 0s 28ms/step - loss: 5.0137e-05 - val_loss: 5.9072e-04 Epoch 22/300 6/6 [==============================] - 0s 29ms/step - loss: 4.8706e-05 - val_loss: 5.4667e-04 Epoch 23/300 6/6 [==============================] - 0s 28ms/step - loss: 4.8973e-05 - val_loss: 5.4473e-04 Epoch 24/300 6/6 [==============================] - 0s 29ms/step - loss: 4.8683e-05 - val_loss: 5.7136e-04 Epoch 25/300 6/6 [==============================] - 0s 29ms/step - loss: 5.0623e-05 - val_loss: 6.3984e-04 Epoch 26/300 6/6 [==============================] - 0s 30ms/step - loss: 6.0414e-05 - val_loss: 8.6026e-04 Epoch 27/300 6/6 [==============================] - 0s 30ms/step - loss: 6.5069e-05 - val_loss: 6.3403e-04 Epoch 28/300 6/6 [==============================] - 0s 28ms/step - loss: 6.5269e-05 - val_loss: 8.0473e-04 Epoch 29/300 6/6 [==============================] - 0s 30ms/step - loss: 6.5151e-05 - val_loss: 6.2235e-04 Epoch 30/300 6/6 [==============================] - 0s 29ms/step - loss: 6.0876e-05 - val_loss: 8.0697e-04 Epoch 31/300 6/6 [==============================] - 0s 28ms/step - loss: 6.1552e-05 - val_loss: 6.3418e-04 Epoch 32/300 6/6 [==============================] - 0s 30ms/step - loss: 5.7528e-05 - val_loss: 5.2875e-04 Epoch 33/300 6/6 [==============================] - 0s 28ms/step - loss: 5.5271e-05 - val_loss: 6.4730e-04 Epoch 34/300 6/6 [==============================] - 0s 27ms/step - loss: 5.1992e-05 - val_loss: 7.8030e-04 Epoch 35/300 6/6 [==============================] - 0s 28ms/step - loss: 5.5727e-05 - val_loss: 5.3203e-04 Epoch 36/300 6/6 [==============================] - 0s 29ms/step - loss: 5.5673e-05 - val_loss: 6.3177e-04 Epoch 37/300 6/6 [==============================] - 0s 29ms/step - loss: 5.1613e-05 - val_loss: 5.2338e-04 Epoch 38/300 6/6 [==============================] - 0s 28ms/step - loss: 5.0783e-05 - val_loss: 5.8298e-04 Epoch 39/300 6/6 [==============================] - 0s 29ms/step - loss: 4.7435e-05 - val_loss: 5.2410e-04 Epoch 40/300 6/6 [==============================] - 0s 29ms/step - loss: 4.7786e-05 - val_loss: 5.3591e-04 Epoch 41/300 6/6 [==============================] - 0s 28ms/step - loss: 4.7503e-05 - val_loss: 5.4940e-04 Epoch 42/300 6/6 [==============================] - 0s 29ms/step - loss: 4.6452e-05 - val_loss: 5.4002e-04 Epoch 43/300 6/6 [==============================] - 0s 30ms/step - loss: 4.6442e-05 - val_loss: 5.1866e-04 Epoch 44/300 6/6 [==============================] - 0s 28ms/step - loss: 4.6059e-05 - val_loss: 5.1688e-04 Epoch 45/300 6/6 [==============================] - 0s 28ms/step - loss: 4.5808e-05 - val_loss: 5.2306e-04 Epoch 46/300 6/6 [==============================] - 0s 28ms/step - loss: 4.6525e-05 - val_loss: 5.1967e-04 Epoch 47/300 6/6 [==============================] - 0s 29ms/step - loss: 4.8092e-05 - val_loss: 5.1659e-04 Epoch 48/300 6/6 [==============================] - 0s 29ms/step - loss: 4.7516e-05 - val_loss: 5.2063e-04 Epoch 49/300 6/6 [==============================] - 0s 28ms/step - loss: 4.5809e-05 - val_loss: 5.1318e-04 Epoch 50/300 6/6 [==============================] - 0s 28ms/step - loss: 4.7254e-05 - val_loss: 5.1308e-04 Epoch 51/300 6/6 [==============================] - 0s 28ms/step - loss: 4.5251e-05 - val_loss: 5.5543e-04 Epoch 52/300 6/6 [==============================] - 0s 28ms/step - loss: 4.5905e-05 - val_loss: 5.1017e-04 Epoch 53/300 6/6 [==============================] - 0s 29ms/step - loss: 4.5034e-05 - val_loss: 5.6716e-04 Epoch 54/300 6/6 [==============================] - 0s 28ms/step - loss: 4.5452e-05 - val_loss: 5.2440e-04 Epoch 55/300 6/6 [==============================] - 0s 27ms/step - loss: 4.7777e-05 - val_loss: 6.3141e-04 Epoch 56/300 6/6 [==============================] - 0s 27ms/step - loss: 5.1305e-05 - val_loss: 5.5474e-04 Epoch 57/300 6/6 [==============================] - 0s 27ms/step - loss: 4.7679e-05 - val_loss: 5.0443e-04 Epoch 58/300 6/6 [==============================] - 0s 28ms/step - loss: 4.5841e-05 - val_loss: 5.0486e-04 Epoch 59/300 6/6 [==============================] - 0s 29ms/step - loss: 4.4836e-05 - val_loss: 5.0822e-04 Epoch 60/300 6/6 [==============================] - 0s 28ms/step - loss: 4.4979e-05 - val_loss: 5.2020e-04 Epoch 61/300 6/6 [==============================] - 0s 28ms/step - loss: 4.4259e-05 - val_loss: 5.0977e-04 Epoch 62/300 6/6 [==============================] - 0s 27ms/step - loss: 4.4635e-05 - val_loss: 7.4517e-04 Epoch 63/300 6/6 [==============================] - 0s 28ms/step - loss: 4.9458e-05 - val_loss: 5.0636e-04 Epoch 64/300 6/6 [==============================] - 0s 27ms/step - loss: 4.9610e-05 - val_loss: 5.0729e-04 Epoch 65/300 6/6 [==============================] - 0s 27ms/step - loss: 4.8559e-05 - val_loss: 6.3253e-04 Epoch 66/300 6/6 [==============================] - 0s 28ms/step - loss: 4.7167e-05 - val_loss: 5.4755e-04 Epoch 67/300 6/6 [==============================] - 0s 27ms/step - loss: 4.7096e-05 - val_loss: 4.9066e-04 Epoch 68/300 6/6 [==============================] - 0s 27ms/step - loss: 4.4310e-05 - val_loss: 4.9044e-04 Epoch 69/300 6/6 [==============================] - 0s 27ms/step - loss: 4.4141e-05 - val_loss: 5.4068e-04 Epoch 70/300 6/6 [==============================] - 0s 27ms/step - loss: 4.9005e-05 - val_loss: 6.0567e-04 Epoch 71/300 6/6 [==============================] - 0s 27ms/step - loss: 4.9279e-05 - val_loss: 5.2227e-04 Epoch 72/300 6/6 [==============================] - 0s 27ms/step - loss: 4.7606e-05 - val_loss: 6.8591e-04 Epoch 73/300 6/6 [==============================] - 0s 28ms/step - loss: 5.4288e-05 - val_loss: 5.7212e-04 Epoch 74/300 6/6 [==============================] - 0s 29ms/step - loss: 5.2279e-05 - val_loss: 4.8281e-04 Epoch 75/300 6/6 [==============================] - 0s 27ms/step - loss: 5.0421e-05 - val_loss: 5.0018e-04 Epoch 76/300 6/6 [==============================] - 0s 27ms/step - loss: 5.0324e-05 - val_loss: 6.8538e-04 Epoch 77/300 6/6 [==============================] - 0s 27ms/step - loss: 5.7253e-05 - val_loss: 6.2901e-04 Epoch 78/300 6/6 [==============================] - 0s 28ms/step - loss: 5.2506e-05 - val_loss: 5.3627e-04 Epoch 79/300 6/6 [==============================] - 0s 28ms/step - loss: 4.8117e-05 - val_loss: 5.5424e-04 Epoch 80/300 6/6 [==============================] - 0s 29ms/step - loss: 4.5993e-05 - val_loss: 5.8062e-04 Epoch 81/300 6/6 [==============================] - 0s 27ms/step - loss: 4.8207e-05 - val_loss: 5.1133e-04 Epoch 82/300 6/6 [==============================] - 0s 37ms/step - loss: 4.9103e-05 - val_loss: 4.7516e-04 Epoch 83/300 6/6 [==============================] - 0s 28ms/step - loss: 4.9031e-05 - val_loss: 7.5069e-04 Epoch 84/300 6/6 [==============================] - 0s 27ms/step - loss: 4.7567e-05 - val_loss: 4.7432e-04 Epoch 85/300 6/6 [==============================] - 0s 27ms/step - loss: 4.3508e-05 - val_loss: 4.7671e-04 Epoch 86/300 6/6 [==============================] - 0s 28ms/step - loss: 4.3062e-05 - val_loss: 4.6603e-04 Epoch 87/300 6/6 [==============================] - 0s 29ms/step - loss: 4.3116e-05 - val_loss: 4.6714e-04 Epoch 88/300 6/6 [==============================] - 0s 28ms/step - loss: 4.3769e-05 - val_loss: 4.9306e-04 Epoch 89/300 6/6 [==============================] - 0s 28ms/step - loss: 4.3359e-05 - val_loss: 5.5865e-04 Epoch 90/300 6/6 [==============================] - 0s 27ms/step - loss: 4.3120e-05 - val_loss: 5.0523e-04 Epoch 91/300 6/6 [==============================] - 0s 28ms/step - loss: 4.3626e-05 - val_loss: 4.6584e-04 Epoch 92/300 6/6 [==============================] - 0s 28ms/step - loss: 4.3846e-05 - val_loss: 5.3466e-04 Epoch 93/300 6/6 [==============================] - 0s 27ms/step - loss: 5.0501e-05 - val_loss: 5.3762e-04 Epoch 94/300 6/6 [==============================] - 0s 27ms/step - loss: 5.2296e-05 - val_loss: 5.5350e-04 Epoch 95/300 6/6 [==============================] - 0s 27ms/step - loss: 4.9425e-05 - val_loss: 4.9249e-04 Epoch 96/300 6/6 [==============================] - 0s 28ms/step - loss: 4.7276e-05 - val_loss: 5.4912e-04 Epoch 97/300 6/6 [==============================] - 0s 28ms/step - loss: 4.1909e-05 - val_loss: 4.5487e-04 Epoch 98/300 6/6 [==============================] - 0s 28ms/step - loss: 4.2255e-05 - val_loss: 4.6518e-04 Epoch 99/300 6/6 [==============================] - 0s 29ms/step - loss: 4.3957e-05 - val_loss: 4.6023e-04 Epoch 100/300 6/6 [==============================] - 0s 28ms/step - loss: 4.2253e-05 - val_loss: 5.0644e-04 Epoch 101/300 6/6 [==============================] - 0s 28ms/step - loss: 4.0570e-05 - val_loss: 4.7234e-04 Epoch 102/300 6/6 [==============================] - 0s 29ms/step - loss: 4.0526e-05 - val_loss: 4.8120e-04 Epoch 103/300 6/6 [==============================] - 0s 28ms/step - loss: 4.0771e-05 - val_loss: 4.4871e-04 Epoch 104/300 6/6 [==============================] - 0s 28ms/step - loss: 4.1719e-05 - val_loss: 4.4550e-04 Epoch 105/300 6/6 [==============================] - 0s 29ms/step - loss: 4.2153e-05 - val_loss: 5.8857e-04 Epoch 106/300 6/6 [==============================] - 0s 27ms/step - loss: 4.3016e-05 - val_loss: 5.0342e-04 Epoch 107/300 6/6 [==============================] - 0s 28ms/step - loss: 4.7574e-05 - val_loss: 4.7303e-04 Epoch 108/300 6/6 [==============================] - 0s 27ms/step - loss: 4.3402e-05 - val_loss: 5.7601e-04 Epoch 109/300 6/6 [==============================] - 0s 27ms/step - loss: 4.5834e-05 - val_loss: 4.3906e-04 Epoch 110/300 6/6 [==============================] - 0s 28ms/step - loss: 4.5280e-05 - val_loss: 4.5233e-04 Epoch 111/300 6/6 [==============================] - 0s 29ms/step - loss: 4.0639e-05 - val_loss: 4.3581e-04 Epoch 112/300 6/6 [==============================] - 0s 28ms/step - loss: 4.1012e-05 - val_loss: 4.4967e-04 Epoch 113/300 6/6 [==============================] - 0s 27ms/step - loss: 4.1113e-05 - val_loss: 5.2586e-04 Epoch 114/300 6/6 [==============================] - 0s 27ms/step - loss: 4.0591e-05 - val_loss: 4.3176e-04 Epoch 115/300 6/6 [==============================] - 0s 27ms/step - loss: 4.0358e-05 - val_loss: 4.7936e-04 Epoch 116/300 6/6 [==============================] - 0s 28ms/step - loss: 3.9503e-05 - val_loss: 4.9555e-04 Epoch 117/300 6/6 [==============================] - 0s 28ms/step - loss: 3.9956e-05 - val_loss: 4.3167e-04 Epoch 118/300 6/6 [==============================] - 0s 27ms/step - loss: 3.9008e-05 - val_loss: 4.3674e-04 Epoch 119/300 6/6 [==============================] - 0s 27ms/step - loss: 3.9271e-05 - val_loss: 5.8607e-04 Epoch 120/300 6/6 [==============================] - 0s 27ms/step - loss: 5.1134e-05 - val_loss: 4.3971e-04 Epoch 121/300 6/6 [==============================] - 0s 28ms/step - loss: 5.1691e-05 - val_loss: 4.6761e-04 Epoch 122/300 6/6 [==============================] - 0s 27ms/step - loss: 4.8591e-05 - val_loss: 5.3190e-04 Epoch 123/300 6/6 [==============================] - 0s 28ms/step - loss: 4.1040e-05 - val_loss: 4.2018e-04 Epoch 124/300 6/6 [==============================] - 0s 28ms/step - loss: 3.9335e-05 - val_loss: 4.8495e-04 Epoch 125/300 6/6 [==============================] - 0s 28ms/step - loss: 4.1402e-05 - val_loss: 4.5981e-04 Epoch 126/300 6/6 [==============================] - 0s 28ms/step - loss: 4.1858e-05 - val_loss: 5.0781e-04 Epoch 127/300 6/6 [==============================] - 0s 38ms/step - loss: 3.8837e-05 - val_loss: 4.3776e-04 Epoch 128/300 6/6 [==============================] - 0s 28ms/step - loss: 4.0212e-05 - val_loss: 4.1703e-04 Epoch 129/300 6/6 [==============================] - 0s 27ms/step - loss: 4.2124e-05 - val_loss: 5.8645e-04 Epoch 130/300 6/6 [==============================] - 0s 28ms/step - loss: 4.6044e-05 - val_loss: 4.1222e-04 Epoch 131/300 6/6 [==============================] - 0s 28ms/step - loss: 4.2733e-05 - val_loss: 4.2163e-04 Epoch 132/300 6/6 [==============================] - 0s 28ms/step - loss: 3.9469e-05 - val_loss: 4.2418e-04 Epoch 133/300 6/6 [==============================] - 0s 28ms/step - loss: 3.7501e-05 - val_loss: 4.3677e-04 Epoch 134/300 6/6 [==============================] - 0s 28ms/step - loss: 3.8176e-05 - val_loss: 4.2952e-04 Epoch 135/300 6/6 [==============================] - 0s 28ms/step - loss: 4.0369e-05 - val_loss: 6.6701e-04 Epoch 136/300 6/6 [==============================] - 0s 27ms/step - loss: 4.9337e-05 - val_loss: 4.0733e-04 Epoch 137/300 6/6 [==============================] - 0s 28ms/step - loss: 4.3170e-05 - val_loss: 4.0414e-04 Epoch 138/300 6/6 [==============================] - 0s 28ms/step - loss: 4.1523e-05 - val_loss: 5.1315e-04 Epoch 139/300 6/6 [==============================] - 0s 28ms/step - loss: 4.0638e-05 - val_loss: 4.1847e-04 Epoch 140/300 6/6 [==============================] - 0s 28ms/step - loss: 4.0677e-05 - val_loss: 4.3206e-04 Epoch 141/300 6/6 [==============================] - 0s 28ms/step - loss: 4.0680e-05 - val_loss: 5.6356e-04 Epoch 142/300 6/6 [==============================] - 0s 28ms/step - loss: 4.2306e-05 - val_loss: 4.1415e-04 Epoch 143/300 6/6 [==============================] - 0s 27ms/step - loss: 4.0676e-05 - val_loss: 3.9718e-04 Epoch 144/300 6/6 [==============================] - 0s 27ms/step - loss: 3.7425e-05 - val_loss: 4.8362e-04 Epoch 145/300 6/6 [==============================] - 0s 28ms/step - loss: 4.0463e-05 - val_loss: 4.2217e-04 Epoch 146/300 6/6 [==============================] - 0s 28ms/step - loss: 3.6883e-05 - val_loss: 3.9380e-04 Epoch 147/300 6/6 [==============================] - 0s 28ms/step - loss: 3.6913e-05 - val_loss: 3.9412e-04 Epoch 148/300 6/6 [==============================] - 0s 28ms/step - loss: 4.0054e-05 - val_loss: 4.6880e-04 Epoch 149/300 6/6 [==============================] - 0s 27ms/step - loss: 3.7090e-05 - val_loss: 3.9191e-04 Epoch 150/300 6/6 [==============================] - 0s 27ms/step - loss: 3.7152e-05 - val_loss: 3.9188e-04 Epoch 151/300 6/6 [==============================] - 0s 28ms/step - loss: 3.5870e-05 - val_loss: 4.0480e-04 Epoch 152/300 6/6 [==============================] - 0s 27ms/step - loss: 3.6648e-05 - val_loss: 3.9267e-04 Epoch 153/300 6/6 [==============================] - 0s 29ms/step - loss: 3.7164e-05 - val_loss: 5.5292e-04 Epoch 154/300 6/6 [==============================] - 0s 28ms/step - loss: 4.0360e-05 - val_loss: 3.8849e-04 Epoch 155/300 6/6 [==============================] - 0s 28ms/step - loss: 3.8028e-05 - val_loss: 4.0467e-04 Epoch 156/300 6/6 [==============================] - 0s 27ms/step - loss: 3.8752e-05 - val_loss: 4.3394e-04 Epoch 157/300 6/6 [==============================] - 0s 28ms/step - loss: 3.6166e-05 - val_loss: 4.1157e-04 Epoch 158/300 6/6 [==============================] - 0s 27ms/step - loss: 3.7406e-05 - val_loss: 3.9664e-04 Epoch 159/300 6/6 [==============================] - 0s 28ms/step - loss: 3.5835e-05 - val_loss: 4.7533e-04 Epoch 160/300 6/6 [==============================] - 0s 28ms/step - loss: 3.7883e-05 - val_loss: 3.7862e-04 Epoch 161/300 6/6 [==============================] - 0s 28ms/step - loss: 3.7002e-05 - val_loss: 4.1774e-04 Epoch 162/300 6/6 [==============================] - 0s 27ms/step - loss: 4.0066e-05 - val_loss: 3.9038e-04 Epoch 163/300 6/6 [==============================] - 0s 27ms/step - loss: 3.7831e-05 - val_loss: 3.7863e-04 Epoch 164/300 6/6 [==============================] - 0s 28ms/step - loss: 3.6573e-05 - val_loss: 3.8238e-04 Epoch 165/300 6/6 [==============================] - 0s 28ms/step - loss: 3.7520e-05 - val_loss: 3.7538e-04 Epoch 166/300 6/6 [==============================] - 0s 27ms/step - loss: 3.5161e-05 - val_loss: 4.0763e-04 Epoch 167/300 6/6 [==============================] - 0s 28ms/step - loss: 3.7949e-05 - val_loss: 3.7453e-04 Epoch 168/300 6/6 [==============================] - 0s 28ms/step - loss: 3.5391e-05 - val_loss: 3.7064e-04 Epoch 169/300 6/6 [==============================] - 0s 27ms/step - loss: 3.7920e-05 - val_loss: 3.6871e-04 Epoch 170/300 6/6 [==============================] - 0s 28ms/step - loss: 3.6607e-05 - val_loss: 4.5369e-04 Epoch 171/300 6/6 [==============================] - 0s 28ms/step - loss: 3.6203e-05 - val_loss: 3.6751e-04 Epoch 172/300 6/6 [==============================] - 0s 28ms/step - loss: 3.5052e-05 - val_loss: 4.9162e-04 Epoch 173/300 6/6 [==============================] - 0s 28ms/step - loss: 3.7034e-05 - val_loss: 3.8094e-04 Epoch 174/300 6/6 [==============================] - 0s 28ms/step - loss: 3.6693e-05 - val_loss: 4.2844e-04 Epoch 175/300 6/6 [==============================] - 0s 28ms/step - loss: 3.6451e-05 - val_loss: 3.9608e-04 Epoch 176/300 6/6 [==============================] - 0s 28ms/step - loss: 3.4949e-05 - val_loss: 3.6128e-04 Epoch 177/300 6/6 [==============================] - 0s 28ms/step - loss: 3.4564e-05 - val_loss: 3.7150e-04 Epoch 178/300 6/6 [==============================] - 0s 37ms/step - loss: 3.5198e-05 - val_loss: 3.7639e-04 Epoch 179/300 6/6 [==============================] - 0s 28ms/step - loss: 3.6648e-05 - val_loss: 3.8561e-04 Epoch 180/300 6/6 [==============================] - 0s 28ms/step - loss: 3.7191e-05 - val_loss: 4.2380e-04 Epoch 181/300 6/6 [==============================] - 0s 28ms/step - loss: 3.8103e-05 - val_loss: 3.6462e-04 Epoch 182/300 6/6 [==============================] - 0s 30ms/step - loss: 3.5416e-05 - val_loss: 6.5856e-04 Epoch 183/300 6/6 [==============================] - 0s 28ms/step - loss: 4.5402e-05 - val_loss: 3.8154e-04 Epoch 184/300 6/6 [==============================] - 0s 28ms/step - loss: 3.5820e-05 - val_loss: 6.0560e-04 Epoch 185/300 6/6 [==============================] - 0s 28ms/step - loss: 4.0189e-05 - val_loss: 4.0743e-04 Epoch 186/300 6/6 [==============================] - 0s 28ms/step - loss: 3.9509e-05 - val_loss: 3.7497e-04 Epoch 187/300 6/6 [==============================] - 0s 28ms/step - loss: 3.7833e-05 - val_loss: 3.7615e-04 Epoch 188/300 6/6 [==============================] - 0s 28ms/step - loss: 3.5893e-05 - val_loss: 3.5360e-04 Epoch 189/300 6/6 [==============================] - 0s 27ms/step - loss: 3.5397e-05 - val_loss: 3.4571e-04 Epoch 190/300 6/6 [==============================] - 0s 31ms/step - loss: 3.4754e-05 - val_loss: 3.7442e-04 Epoch 191/300 6/6 [==============================] - 0s 28ms/step - loss: 3.3364e-05 - val_loss: 3.7269e-04 Epoch 192/300 6/6 [==============================] - 0s 28ms/step - loss: 3.3811e-05 - val_loss: 3.9378e-04 Epoch 193/300 6/6 [==============================] - 0s 27ms/step - loss: 3.5349e-05 - val_loss: 3.4427e-04 Epoch 194/300 6/6 [==============================] - 0s 30ms/step - loss: 3.8081e-05 - val_loss: 4.5326e-04 Epoch 195/300 6/6 [==============================] - 0s 31ms/step - loss: 3.5818e-05 - val_loss: 3.8512e-04 Epoch 196/300 6/6 [==============================] - 0s 29ms/step - loss: 3.6307e-05 - val_loss: 3.8736e-04 Epoch 197/300 6/6 [==============================] - 0s 27ms/step - loss: 3.4238e-05 - val_loss: 3.4454e-04 Epoch 198/300 6/6 [==============================] - 0s 28ms/step - loss: 3.4051e-05 - val_loss: 3.4162e-04 Epoch 199/300 6/6 [==============================] - 0s 28ms/step - loss: 3.5975e-05 - val_loss: 3.7907e-04 Epoch 200/300 6/6 [==============================] - 0s 27ms/step - loss: 3.4723e-05 - val_loss: 3.5411e-04 Epoch 201/300 6/6 [==============================] - 0s 27ms/step - loss: 3.5441e-05 - val_loss: 3.4065e-04 Epoch 202/300 6/6 [==============================] - 0s 28ms/step - loss: 3.2994e-05 - val_loss: 3.3443e-04 Epoch 203/300 6/6 [==============================] - 0s 29ms/step - loss: 3.2386e-05 - val_loss: 3.3433e-04 Epoch 204/300 6/6 [==============================] - 0s 29ms/step - loss: 3.2532e-05 - val_loss: 4.9409e-04 Epoch 205/300 6/6 [==============================] - 0s 27ms/step - loss: 3.6390e-05 - val_loss: 3.5703e-04 Epoch 206/300 6/6 [==============================] - 0s 27ms/step - loss: 3.7373e-05 - val_loss: 3.7756e-04 Epoch 207/300 6/6 [==============================] - 0s 27ms/step - loss: 3.8520e-05 - val_loss: 3.7989e-04 Epoch 208/300 6/6 [==============================] - 0s 27ms/step - loss: 3.7669e-05 - val_loss: 3.5140e-04 Epoch 209/300 6/6 [==============================] - 0s 27ms/step - loss: 3.4343e-05 - val_loss: 4.0296e-04 Epoch 210/300 6/6 [==============================] - 0s 27ms/step - loss: 3.4826e-05 - val_loss: 3.3830e-04 Epoch 211/300 6/6 [==============================] - 0s 27ms/step - loss: 3.4411e-05 - val_loss: 3.2794e-04 Epoch 212/300 6/6 [==============================] - 0s 27ms/step - loss: 3.3735e-05 - val_loss: 3.2816e-04 Epoch 213/300 6/6 [==============================] - 0s 27ms/step - loss: 3.2009e-05 - val_loss: 3.8783e-04 Epoch 214/300 6/6 [==============================] - 0s 27ms/step - loss: 3.2901e-05 - val_loss: 3.4561e-04 Epoch 215/300 6/6 [==============================] - 0s 28ms/step - loss: 3.2039e-05 - val_loss: 3.2541e-04 Epoch 216/300 6/6 [==============================] - 0s 27ms/step - loss: 3.1737e-05 - val_loss: 3.3265e-04 Epoch 217/300 6/6 [==============================] - 0s 27ms/step - loss: 3.1533e-05 - val_loss: 3.2900e-04 Epoch 218/300 6/6 [==============================] - 0s 28ms/step - loss: 3.1495e-05 - val_loss: 3.7068e-04 Epoch 219/300 6/6 [==============================] - 0s 27ms/step - loss: 3.1388e-05 - val_loss: 3.3259e-04 Epoch 220/300 6/6 [==============================] - 0s 27ms/step - loss: 3.1156e-05 - val_loss: 4.0736e-04 Epoch 221/300 6/6 [==============================] - 0s 27ms/step - loss: 3.1986e-05 - val_loss: 3.2558e-04 Epoch 222/300 6/6 [==============================] - 0s 35ms/step - loss: 3.2770e-05 - val_loss: 4.9332e-04 Epoch 223/300 6/6 [==============================] - 0s 27ms/step - loss: 3.5997e-05 - val_loss: 3.2944e-04 Epoch 224/300 6/6 [==============================] - 0s 27ms/step - loss: 3.3435e-05 - val_loss: 4.8294e-04 Epoch 225/300 6/6 [==============================] - 0s 27ms/step - loss: 3.4517e-05 - val_loss: 3.3350e-04 Epoch 226/300 6/6 [==============================] - 0s 27ms/step - loss: 3.1024e-05 - val_loss: 3.2739e-04 Epoch 227/300 6/6 [==============================] - 0s 28ms/step - loss: 3.0829e-05 - val_loss: 3.1635e-04 Epoch 228/300 6/6 [==============================] - 0s 28ms/step - loss: 3.1500e-05 - val_loss: 3.6727e-04 Epoch 229/300 6/6 [==============================] - 0s 27ms/step - loss: 3.1012e-05 - val_loss: 3.1509e-04 Epoch 230/300 6/6 [==============================] - 0s 27ms/step - loss: 3.0797e-05 - val_loss: 3.9436e-04 Epoch 231/300 6/6 [==============================] - 0s 28ms/step - loss: 3.1639e-05 - val_loss: 3.3696e-04 Epoch 232/300 6/6 [==============================] - 0s 27ms/step - loss: 3.0828e-05 - val_loss: 3.5289e-04 Epoch 233/300 6/6 [==============================] - 0s 27ms/step - loss: 3.1682e-05 - val_loss: 3.9576e-04 Epoch 234/300 6/6 [==============================] - 0s 27ms/step - loss: 3.4716e-05 - val_loss: 3.7956e-04 Epoch 235/300 6/6 [==============================] - 0s 27ms/step - loss: 3.9644e-05 - val_loss: 5.6274e-04 Epoch 236/300 6/6 [==============================] - 0s 28ms/step - loss: 3.5305e-05 - val_loss: 3.1149e-04 Epoch 237/300 6/6 [==============================] - 0s 28ms/step - loss: 3.1806e-05 - val_loss: 3.6977e-04 Epoch 238/300 6/6 [==============================] - 0s 29ms/step - loss: 3.2046e-05 - val_loss: 3.1771e-04 Epoch 239/300 6/6 [==============================] - 0s 28ms/step - loss: 3.1964e-05 - val_loss: 3.1637e-04 Epoch 240/300 6/6 [==============================] - 0s 27ms/step - loss: 3.0958e-05 - val_loss: 3.5127e-04 Epoch 241/300 6/6 [==============================] - 0s 27ms/step - loss: 3.2261e-05 - val_loss: 3.0755e-04 Epoch 242/300 6/6 [==============================] - 0s 27ms/step - loss: 3.4718e-05 - val_loss: 4.4235e-04 Epoch 243/300 6/6 [==============================] - 0s 27ms/step - loss: 3.4675e-05 - val_loss: 3.1811e-04 Epoch 244/300 6/6 [==============================] - 0s 27ms/step - loss: 3.3075e-05 - val_loss: 3.8481e-04 Epoch 245/300 6/6 [==============================] - 0s 27ms/step - loss: 3.0910e-05 - val_loss: 3.2136e-04 Epoch 246/300 6/6 [==============================] - 0s 27ms/step - loss: 3.3528e-05 - val_loss: 4.6475e-04 Epoch 247/300 6/6 [==============================] - 0s 27ms/step - loss: 3.6748e-05 - val_loss: 3.0626e-04 Epoch 248/300 6/6 [==============================] - 0s 29ms/step - loss: 3.2193e-05 - val_loss: 3.0778e-04 Epoch 249/300 6/6 [==============================] - 0s 28ms/step - loss: 3.0542e-05 - val_loss: 3.7856e-04 Epoch 250/300 6/6 [==============================] - 0s 28ms/step - loss: 3.1912e-05 - val_loss: 3.0847e-04 Epoch 251/300 6/6 [==============================] - 0s 27ms/step - loss: 3.5287e-05 - val_loss: 3.2022e-04 Epoch 252/300 6/6 [==============================] - 0s 27ms/step - loss: 3.1589e-05 - val_loss: 3.1819e-04 Epoch 253/300 6/6 [==============================] - 0s 27ms/step - loss: 2.9823e-05 - val_loss: 3.0381e-04 Epoch 254/300 6/6 [==============================] - 0s 27ms/step - loss: 3.0014e-05 - val_loss: 3.6404e-04 Epoch 255/300 6/6 [==============================] - 0s 28ms/step - loss: 3.2922e-05 - val_loss: 3.0589e-04 Epoch 256/300 6/6 [==============================] - 0s 28ms/step - loss: 2.9711e-05 - val_loss: 4.4349e-04 Epoch 257/300 6/6 [==============================] - 0s 27ms/step - loss: 3.3159e-05 - val_loss: 3.6379e-04 Epoch 258/300 6/6 [==============================] - 0s 28ms/step - loss: 3.3526e-05 - val_loss: 3.0306e-04 Epoch 259/300 6/6 [==============================] - 0s 28ms/step - loss: 3.0376e-05 - val_loss: 3.5862e-04 Epoch 260/300 6/6 [==============================] - 0s 27ms/step - loss: 2.9825e-05 - val_loss: 3.1904e-04 Epoch 261/300 6/6 [==============================] - 0s 27ms/step - loss: 3.1879e-05 - val_loss: 3.4188e-04 Epoch 262/300 6/6 [==============================] - 0s 37ms/step - loss: 3.3935e-05 - val_loss: 3.5108e-04 Epoch 263/300 6/6 [==============================] - 0s 27ms/step - loss: 3.0101e-05 - val_loss: 3.0878e-04 Epoch 264/300 6/6 [==============================] - 0s 28ms/step - loss: 2.9251e-05 - val_loss: 2.9988e-04 Epoch 265/300 6/6 [==============================] - 0s 28ms/step - loss: 2.9135e-05 - val_loss: 3.1429e-04 Epoch 266/300 6/6 [==============================] - 0s 27ms/step - loss: 3.1148e-05 - val_loss: 3.2367e-04 Epoch 267/300 6/6 [==============================] - 0s 28ms/step - loss: 3.0476e-05 - val_loss: 2.9820e-04 Epoch 268/300 6/6 [==============================] - 0s 28ms/step - loss: 2.9238e-05 - val_loss: 3.2258e-04 Epoch 269/300 6/6 [==============================] - 0s 27ms/step - loss: 2.9202e-05 - val_loss: 2.9815e-04 Epoch 270/300 6/6 [==============================] - 0s 27ms/step - loss: 3.1455e-05 - val_loss: 3.2140e-04 Epoch 271/300 6/6 [==============================] - 0s 27ms/step - loss: 2.9394e-05 - val_loss: 3.6962e-04 Epoch 272/300 6/6 [==============================] - 0s 27ms/step - loss: 3.0026e-05 - val_loss: 3.0022e-04 Epoch 273/300 6/6 [==============================] - 0s 28ms/step - loss: 3.0705e-05 - val_loss: 4.9474e-04 Epoch 274/300 6/6 [==============================] - 0s 28ms/step - loss: 3.4969e-05 - val_loss: 3.0065e-04 Epoch 275/300 6/6 [==============================] - 0s 27ms/step - loss: 3.1780e-05 - val_loss: 3.2616e-04 Epoch 276/300 6/6 [==============================] - 0s 27ms/step - loss: 3.0128e-05 - val_loss: 3.0402e-04 Epoch 277/300 6/6 [==============================] - 0s 27ms/step - loss: 3.4030e-05 - val_loss: 6.9602e-04 Epoch 278/300 6/6 [==============================] - 0s 28ms/step - loss: 4.2202e-05 - val_loss: 3.0068e-04 Epoch 279/300 6/6 [==============================] - 0s 27ms/step - loss: 3.0910e-05 - val_loss: 3.0203e-04 Epoch 280/300 6/6 [==============================] - 0s 28ms/step - loss: 3.0341e-05 - val_loss: 3.4467e-04 Epoch 281/300 6/6 [==============================] - 0s 27ms/step - loss: 3.5805e-05 - val_loss: 2.9584e-04 Epoch 282/300 6/6 [==============================] - 0s 27ms/step - loss: 3.1648e-05 - val_loss: 3.5150e-04 Epoch 283/300 6/6 [==============================] - 0s 28ms/step - loss: 3.4300e-05 - val_loss: 3.0483e-04 Epoch 284/300 6/6 [==============================] - 0s 27ms/step - loss: 2.8822e-05 - val_loss: 3.5656e-04 Epoch 285/300 6/6 [==============================] - 0s 27ms/step - loss: 3.6199e-05 - val_loss: 6.8535e-04 Epoch 286/300 6/6 [==============================] - 0s 27ms/step - loss: 4.1642e-05 - val_loss: 3.7541e-04 Epoch 287/300 6/6 [==============================] - 0s 27ms/step - loss: 3.8214e-05 - val_loss: 4.0116e-04 Epoch 288/300 6/6 [==============================] - 0s 27ms/step - loss: 3.2742e-05 - val_loss: 2.9232e-04 Epoch 289/300 6/6 [==============================] - 0s 27ms/step - loss: 2.9566e-05 - val_loss: 3.0349e-04 Epoch 290/300 6/6 [==============================] - 0s 29ms/step - loss: 2.8411e-05 - val_loss: 3.5827e-04 Epoch 291/300 6/6 [==============================] - 0s 27ms/step - loss: 2.9510e-05 - val_loss: 3.1645e-04 Epoch 292/300 6/6 [==============================] - 0s 28ms/step - loss: 3.2016e-05 - val_loss: 4.0342e-04 Epoch 293/300 6/6 [==============================] - 0s 27ms/step - loss: 3.0703e-05 - val_loss: 2.9043e-04 Epoch 294/300 6/6 [==============================] - 0s 27ms/step - loss: 3.1408e-05 - val_loss: 2.9512e-04 Epoch 295/300 6/6 [==============================] - 0s 27ms/step - loss: 2.8574e-05 - val_loss: 3.0567e-04 Epoch 296/300 6/6 [==============================] - 0s 35ms/step - loss: 2.8477e-05 - val_loss: 3.2119e-04 Epoch 297/300 6/6 [==============================] - 0s 29ms/step - loss: 2.9123e-05 - val_loss: 3.8052e-04 Epoch 298/300 6/6 [==============================] - 0s 27ms/step - loss: 3.2265e-05 - val_loss: 3.0611e-04 Epoch 299/300 6/6 [==============================] - 0s 27ms/step - loss: 2.9846e-05 - val_loss: 3.6055e-04 Epoch 300/300 6/6 [==============================] - 0s 28ms/step - loss: 2.9634e-05 - val_loss: 2.9422e-04
# Plotting Loss Curve
plotLossCurve(history1,"red", "Model 1 Loss")
# Evaluating model
MAE1, MAPE1, MDAPE1, y_pred1= eval(model1, x_test1, y_test1, scaler_pred1)
22/22 [==============================] - 1s 18ms/step Median Absolute Error (MAE): 1.79 Mean Absolute Percentage Error (MAPE): 1.55 % Median Absolute Percentage Error (MDAPE): 1.12 %
# Visualising Predictions
visualizePreds(data_filtered1, train_data_len1, y_pred1, date_index1, "orange")
predictFuturePrice(model1, df, sequence_length1, features1, scaler1, scaler_pred1)
1/1 [==============================] - 0s 28ms/step The close price for GOOG at 2023-10-19 was 139.28 The predicted close price is 140.5500030517578 (+0.9%)
/tmp/ipykernel_15950/3096130203.py:16: FutureWarning: Series.__getitem__ treating keys as positions is deprecated. In a future version, integer keys will always be treated as labels (consistent with DataFrame behavior). To access a value by position, use `ser.iloc[pos]` price_today = np.round(new_df['Close'][-1], 2)
import os
import csv
import json
import datetime
import pandas as pd
from tqdm import tqdm
import snscrape.modules.twitter as sntwitter
path = "./GOOG_tweets.json"
if os.path.isfile(stockname + '_tweets.json'):
print("File already exits...no need to scrape it again")
print("To scrape again, delete : " + stockname + '_tweets.json')
else:
maxTweets = 3
start_date = date_start.date()
period = (date_today - start_date).days
tweets = dict()
for i in tqdm(range(period)):
dayTweets=list()
start_interval = start_date
end_interval = start_interval + datetime.timedelta(days=1)
try:
for i,tweet in enumerate(sntwitter.TwitterSearchScraper('#Apple + OR @Apple + since:' + str(start_interval) + ' until:' + str(end_interval) +' -filter:links -filter:replies lang:"en" ').get_items()):
if i > maxTweets :
break
dayTweets.append(tweet.content)
key = start_date.strftime('%d/%m/%Y')
tweets[key] = dayTweets
start_date += datetime.timedelta(days=1)
except Exception as e:
print(i,e)
pass
with open( stockname + '_tweets.json', 'w') as fp:
json.dump(tweets, fp)
df_senti = pd.read_csv('GOOG_senti_scores.csv')
df_senti.set_index('Date', inplace=True)
df2 = df.join(df_senti, how='inner')
df2.head()
Open | High | Low | Close | Adj Close | Volume | Unnamed: 0 | NEG | NEU | POS | |
---|---|---|---|---|---|---|---|---|---|---|
Date |
import json
f = open(stockname + '_tweets.json',)
data = json.load(f)
dates = list()
NEG = list()
NEU = list()
POS = list()
for key in tqdm(data):
reviews = data[key]
pos=0
neg=0
neu=0
cnt=0
for text in reviews:
cnt=cnt+1
text = preprocess(text)
encoded_input = tokenizer(text, return_tensors='pt')
output = model(**encoded_input)
scores = output[0][0].detach().numpy()
scores = softmax(scores)
neg=neg+scores[0]
neu=neu+scores[1]
pos=pos+scores[2]
NEG.append(neg/cnt)
NEU.append(neu/cnt)
POS.append(pos/cnt)
dates.append(datetime.strptime(str(key), "%d/%m/%Y"))
import csv
import json
import datetime
import pandas as pd
from tqdm import tqdm
import snscrape.modules.twitter as sntwitter
if os.path.isfile(stockname + '_tweets.json'):
print("File already exists...no need to scrape it again")
print("To scrape again, delete : " + stockname + '_tweets.json')
else:
maxTweets = 3
start_date = date_start.date()
period = (date_today - start_date).days
tweets = dict()
for i in tqdm(range(period)):
dayTweets=list()
start_interval = start_date
end_interval = start_interval + datetime.timedelta(days=1)
try:
for i,tweet in enumerate(sntwitter.TwitterSearchScraper('#Google + OR @Google + since:' + str(start_interval) + ' until:' + str(end_interval) +' -filter:links -filter:replies lang:"en" ').get_items()):
if i > maxTweets :
break
dayTweets.append(tweet.content)
key = start_date.strftime('%d/%m/%Y')
tweets[key] = dayTweets
start_date += datetime.timedelta(days=1)
except Exception as e:
print(i,e)
pass
with open( stockname + '_tweets.json', 'w') as fp:
json.dump(tweets, fp)
import os, csv
import urllib.request
from scipy.special import softmax
from transformers import AutoModelForSequenceClassification
from transformers import TFAutoModelForSequenceClassification
from transformers import AutoTokenizer