Predict Google Stock Price using Recurrent Neural networks

Rajitha Gunathilake
4 min readJun 20, 2021

Google Stock Price Data Set consists of data about Google stock prices from 2012 to 2016 . dataset consists of “Date “ , “Open”, “ High”, “Low”, “ Close” , “Volume” columns . The classification goal is to predict the Open value for future data using Recurrent neural network approach . this dataset is available in kaggle .

first we will load the dataset to a pandas data frame and print the head.

here we can take a look at our data . next we will print out the info about the data frame .

by lookin at info we can see that volume , and close features are object typed so first we have to convert them to float.

after converting , visualize the data in a line plot.

here we can see that close value has a outlier , because close value cannot be larger that the high value for a give time step .here we cannot remove the outlier values because that is around 40% of the data set . so we will remove close feature from the dataset .

check for any missing values in the dataset

for the training and prediction I will use ‘Volume’ feature .

convert the volume attribute to float and the scale the volume to be divided by a factor of thousand , since volume is in large numbers .

to feed into the Recurrent neural network we have to transform continuous data into time steps . first we will convert sequence into steps . and then split data into training and test partitions .

after splitting the data , output will be an new value at the end of and array tailing with previous values until the given steps is filled

after this step we have to reshape the data to [samples, timesteps, features] format because that is the format supported by the RNN model. here i used timesteps as 5 , and features as one because we only uses ‘open’ feature .

here data is split into 80% training 20% test ratio.

next define the RNN model with LSTM cells , and dense connected layers .

after training the model for about 100 epochs we can see that validation mean square error is decreasing indicating that the model is training .

after training , when evaluating the model , following results .

R2 score

plot of the actual test data and models predictions

model tainting history . epoch vs mean absolute error

epoch vs model loss

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

No responses yet

Write a response