Bitcoin Price Prediction using RNN LSTM

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
so hello and welcome guys this is milisha gupta and we are going to learn about the prediction of bitcoin price using lstm and rnn in my previous video we have learned about the we have gained the theoretical knowledge of lsdn bitcoin as well as rnn so in this video we are going to concentrate specially on the implementation part so starting off for the implementation let's begin first of all let's import all the necessary libraries that we are going to require for this project namely we have started off with the data manipulation libraries that is the numpy and pandas moving forward for the data visualization libraries we have used smart plot 11 c1 so after importing the libraries let's have a look at what a data set is going to be going for the data set let's come to the data exploration part for the data exploration part i have used the data set from the yahoo finance official website you can click on the on this link i will provide this link in the description box so you can find the link click the link you can get your own set of data set uh this is this data set contains all the columns that you can see here that is currency date closing price opening price high low all this data is going to be there uh it is going to be from the least of the years that is in my case it is from 2013 to the latest time that is till today you can find your data set till today from there otherwise you can find my data set from my github repository uh the link of the github repository i've uh presented in the description box you can click on the link and get the data set so for this i have used the url of my data set and put it into the variable known as path 2 and this then i have executed this path 2 variable with the help of read csc command and this csv file is imported ok after importing the csv file what we have done is we will actually sort this data set according to the date we will sort it in ascending order let's have a quick look what our data set looks like you see here for showing the top five rows of your data frame here you use the dot head command and for the last five rows you use the dot tail command so the top five looks like it is from the year 2013 and all the closing price opening price high and lows are given in this and let's have a look till where the data is present it is present till 1704 2021 that is the latest latest data is available in this data set okay moving forward let's go to what are we actually looking for let's see what our target data set is coming to the target data set here you can see that i have chosen the closing price column from the above data set and stored it in a new data frame that i have created a new data frame called price here okay so this is going to be the target data that we are going to work on okay let's first of all plot this data let's see how we plot we plotted with the help of matplotlib we provide the uh uh x takes y takes x label y labels and let's see how it looks so you can see here a graph is plotted for all these years starting from 2013 ending till 2021 and you can see there is a great fluctuation in the prices of bitcoin after the year 2020 there's a sudden increase in the price of bitcoins okay moving forward let's have a look how a price data set actually looks like uh initially we were looking at this data set now we have sorted and dropped the data set and this is how it actually looks like see the top five rows the remaining five rows let's have a better summary of this data set you can get the summary of this data set by using the dot info method so you see here what we uh what it is providing the information you can see there are 2755 non-null values and the data type of this variable is float 64. you see these are decimal values right okay let's move forward for the data preparation now data preparation coming to normalization normalization is one of the very important steps in forming a model see if you do not normalize your data what happens is the accuracy is actually disrupted you cannot expect a good uh accuracy if you like do not normalize your data what what is the reason behind this is see what were the prices let's have a look there were prices ranging from hundreds to sixty two thousand sixty one thousand so you see there is a drastic difference of the between the prices in order to get a normalized data in order to get a refined output we what we do is we normalize the data we uh like input these huge values and uh transform these values into uh values between 0 and 10. we use we do it by importing minimax scalar from the sql on pre-processing package so what this does here it actually inputs the data it inputs the prices hundreds and thousand and it normalizes them to values between 0 to 10 so and also uh keep in mind that you can alter this you can like type 0 comma 1 now this is going to result in values between the 0 and 1 okay for now by default what it does is it uh transforms the value between 0 to 10 okay you see you you can see what result have been shown okay uh to get a closer look let's like randomly select any of the any of the data points we have randomly selected the zero data point 500 data point and the 900 data point so you can see here what is the actual price that was before normalization whereas the price after normalization you see there are differences in the price this is 0.000 after normalization and this is 123.65 that is hundreds are converted to 0.000 values so you see and there are all the values like 900 somethings these are values corresponding to 61 thousands great values like that okay so after we have seen the data normalization let's move forward to a very important part that is the data splitting so why are we going to split the data okay during this step we are going to tackle with two very important problems what happens is the first problem being we have to split our data what happens is the data set we are taking we need to clip it up and crop it up into two sets that is the training set and the testing set so what is the training set the training set data will be used to teach a model you're going to train your entire model based on this training set and this is uh ideally we use it like eighty percent for training and the remaining of this uh set that is the twenty percent we use it for testing purposes the testing data is actually used as a baseline comparison for our predictions what is baseline comparison for predictions this means the testing data provides you a asset like if you do not know what should ideally be the value uh what should be the value of the outcome then how are you going to see that the prediction that your model has done is right or wrong so for that purpose for the comparison purpose what we do is we take uh we use the test data and compare it with the predictions that a model will be will be giving okay in addition here we uh what we do is we prepare the lstm network this particular type of networks requires us to send the time series chunks of data separating the history data we use for training whereas the target data which we are going to use to predict them uh predict the future outcomes let's see what we have done for tree uh for splitting the variables sorry splitting the data set so we have formatted a def univariate function what we have done is we have created a univariate data function that accepts the data set starting index ending index the history size and the target size we'll talk about these later the target size and the history size let's see the implementation here is the implementation of univariate data this will actually split your data based on the starting and the last input then we define the past and future past and future target variables so what are these variables responsible for see you can clearly see the past history here we have uh given us five so what does this mean this means we need to use five days of data to learn to predict the next point in the time series what is the next time in the time series this is the future target for now we are doing it as zero okay after we have uh run this after we have created this variable we need to call this function we need to call this function using the univariate data and passing the parameters to this function before that before we pass the parameters we should know the end index of the training data set to get the end index of the training data set we do the we get the length here you uh 0.8 signifies eighty percent of the data this this will return the index the last index of the training data set which will get stored in the train split so we'll pass it here this is the data set this is the starting index this is the ending index that we calculated just right now then there is the past history and the future target that we have defined here okay similarly we'd follow the above steps for the test data x data and y data let's move forward after we split the data now the very important step is building the model what model are we going to use the lstm model so what happens is you know uh what happens is the to find out the right model is actually like an art it takes several tries plus experience to find out the right layers and hyper parameters if you don't have enough experience you cannot play with them we cannot uh adjust them to find out what hyper parameters are the best for you you know okay let's see what we have done uh actually we are not talking about uh the details of how we have used them we will not go in the depth if you want uh to learn more about them i will provide the links of uh the further descriptions and blogs of the topics on choosing the right hyper parameters in the description box for now let's carry on with our own model so to import our lsd model we'll be importing keras what is a machine learning library that is that we are using to import our lstm model so from lstm we are going to import the sequential model uh this is sequential for importing the sequential model then we are importing add from the optimizers part then we are uh like importing lstm leaky value drop a dropout layer from the get-grass dot layer part so these are the hyperparameters you see here the hyperparameters that we have chosen for a model so let's study about them this is the number of units that is the number of neurons that are going to be used and there is learning rate uh that is 0.0001 that there is the activation function for here this part we are using the sigmoid activation function but there are many data then there are many activation functions which are present in the uh like machine learning uh but that entirely depends on like what the problem is for our problem the sigmoid function fits perfectly so for uh the optimizer we are using adam for the lowest function we are using mean square error what is mse the mean square error the batch size we are using is five and the number of epochs we are using 250. here is a little fact that i would like to give to you all you see uh the more the number of epochs that uh that you are going to train your model on the better will be the accuracy but here let's be cautious and if you like uh increase the number of epochs to a very great number then it is obviously going to overfit your model and we do not ah and we are not looking for overfitting here so choose uh like play with this value and see how your predicted values are coming uh after you have a better knowledge of now the number of box after you have experimented with this number you will finally get your perfect accuracy as well as the perfect predicted values okay moving forward what we're doing is let's initialize the rnn the rna model that we have built let's initialize it using the model equal to sequential method then we import all the layers so sequential voice sequential actually in keras we simply stack multiple layers on top of others this means we are doing it in a sequence therefore we are initializing the sequential model okay after importing the layers and everything we compile this rnn using the optimizer atom and the loss function that we stated as mean squared error okay now to like you have built this model now to get the summary of this model what you are going to do you can put this method dot summary method apply this to the model variable and here you see you can find out the entire architecture of your model that you have built see yeah here okay okay after looking at the architecture you see uh what here they have defined this is the number of total parameters trainable parameters non-trainable parameters the entire information is present here okay the very important part is here now that is training the model whatever the training data that was split in the upper function using the univariate function we are going to fit that we are going to transform that into the model okay now this history variable is used for fitting the training data remember that and here are the hyper parameters that we have stated above you see a validation split equal to zero point zero one the path size we have already given number of epochs we have already given and the very important uh point to keep in mind here is the shuffle the shuffle should be set to false this the reason behind this is this cannot be true is uh we are working right now on a sequential motor so you know uh when you're working on a chronological model you cannot alter the dates it is going to mess up the outputs of the model so make sure you do not put this shuffle to true make sure it is put to false so here you can see uh all artworks have been trained from all the 250 epochs have been trained yeah moving forward after the training of epoch let's calculate the loss for our training data set that is history.history loss let's figure out the laws of this training data set let's figure out the validation loss okay so to visualize it clearly we are going to plot this into a graph the what uh what happens here is see the blue one is the training loss and the red one is the validation loss to get a better accuracy with your model what happens here the gap between these two graphs should be minimum see as you can see there is a very less there is a very less gap between both of these graphs so make sure this graph the space between the graphs is very less okay let's see let's have a look at what a prediction looks like and what our outcome has come finally we have reached the prediction but for the prediction part what we are doing is see in the original one we are going to transform the testing value that is the value that we uh split it the last remaining twenty percent of the value that we get for the testing threat this is the value see and then here you see this is the predictions value what is predictions predictions will uh contain the values you see here the model dot date x test okay now this will contain the predicted values based on the testing set so let's see let's have a look at how our outcome has become we have plotted this graph using c1 library and this is a wonderful graph that is presented here we can see that the accuracy is quite good as for now the prediction is quite nice there is not very much deviation or the difference between the predicted and uh the test data so here with this we come to the end of our project before any further doubts you can contact me uh you can drop your doubts on the comments section and for other various links that are related to this project i will drop in the description box so i hope this was great learning to you thank you guys and have a nice day
Info
Channel: MILISHA GUPTA
Views: 1,634
Rating: 4.7538462 out of 5
Keywords:
Id: qpZ-dKPaj8M
Channel Id: undefined
Length: 19min 20sec (1160 seconds)
Published: Sun Apr 18 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.