Keras bitcoin

Recurrent Neural Network (LSTM) by using TensorFlow and Keras in Python for BitCoin price prediction - Abhay64/RNN-for-BitCoin-price-prediction.
Table of contents

We are using pandas to read the. The decision made here is just for the purpose of this tutorial. We have picked the training set to be 30 days which means that we are going to test our model over the last month. I recommend reading this Stackoverflow answer for clarification. Essentially, that is made because we are using Recurrent neural network. This way we are creating a sequence — exactly what RNNs need for training. If you need more information about how these wonderful networks work, you may find one of my posts useful. Now we need to train our model using the above data.

With keras , this process is extremely easy and understandable. However, if you are interested in diving into equations and algorithms, you can find more information here LSTM network and here GRU network. We are building the model as follows:.

After explaining what each hyperparameter means, we start training the model:. Finally we came to the long-awaited moment of predicting the price.

Curiousily

We have 2 steps: predict the price and plot it to compare with the real results. As you already saw, Keras makes everything so easy. Here the case remains the same:. Lines 1—6: we do exactly the same as for the training set.


  • can i cash out my bitcoins.
  • bitcoin revolution website;
  • empresas que aceitam bitcoin no brasil!
  • portales bitcoin;
  • How to Predict Bitcoin Price with Deep Learning LSTM Network: (1) The Benchmark Model.
  • .66 btc to usd.
  • Pin on Technology (Group Board)!

Line 7: predict. Line 8: rescale the predicted data to match its real values prices in USD. Finally, we are going to plot test and predicted prices using the below snippet:. The results happen to be really interesting. Of course, the accuracy of prediction is not excellent but still, it is cool to be seen:. Obsessed with creating a positive impact.

Love blogging about AI and reading books. Every Thursday, the Variable delivers the very best of Towards Data Science: from hands-on tutorials and cutting-edge research to original features you don't want to miss. Take a look. Review our Privacy Policy for more information about our privacy practices.

Introductory concepts

Check your inbox Medium sent you an email at to complete your subscription. Your home for data science. A Medium publication sharing concepts, ideas and codes. These variables are the input and output variables respectively for our Neural Network. The input is the number of periods to look back and the output is the number of periods ahead.

Simply put, the input periods are used to figure out patterns and sequences that lead to the output periods. They both can be any number but it would probably be beneficial if the number of input periods are greater than the output periods. This function makes up the bulk of our network.

Bitcoin price prediction using LSTM

The importance of this function will be explained later on. The number of periods in and out can be any number of our choosing. But for the sake of this example, we will choose to look back on 30 days of price history to predict the next 10 days. It means that for each day of the 1, days we selected, the previous 30 days are used to determine any patterns or sequences that lead to the next 10 days. These values are used to train the Neural Network so that we can predict or forecast the next 10 days of Bitcoin prices from today.

Now that we have our data ready to go, we can move on to the fun part — building the Neural Network. Our Neural Network will be created using a simple Sequential model from the Keras library. With everything ready, we can start constructing the Neural Network for our Bitcoin price data:. To begin, we instantiate the Sequential model and an activation function, which runs throughout the layers in the Neural Network.

The first layer in our Network will be the input layer , which can be added to the Network by simply calling model. Inside the. For the next item, we can begin creating our hidden layers within the Neural Network.

Predicting the Price of Bitcoin, Intro to LSTM

In order to avoid typing out model. It also has the option to add in Dropout layers , which is important for regularization. If you are not familiar with the term regularization , just know that it is a method of preventing overfitting in our Neural Network. Overfitting , simply put, occurs when a model performs poorly when predicting new observations and in our case, future Bitcoin prices. This is done so that the dimensions from the final hidden layer can proceed smoothly to the output layer with no errors.

The next two items in our code snippet above contain the final layer and a summary of the Neural Network we just created. The model summary displays basic information regarding the created Neural Network. Before we move on to training our NN, we must compile it with the preferred specifications:. When it comes to creating the NN model, plenty of experimentation will be necessary in order to find the best combination of parameters. The number of nodes and layers are especially important when it comes to how the model will perform in the end.

There is no magic number for either and both require their own ideal number that must be discovered through trial and error. Nearly every NN you create for any new dataset must be composed with their own unique set of parameters. Because of this experimentation process, our results may drastically differ from one NN to the next depending on the dataset used. We can accomplish this by writing just one line of code:. Once we run this code, our Neural Network will begin training on our Bitcoin price data. Depending on the resources we have, the time to train may take several hours.

Those with better hardware specifications may arrive at better results than us. In the meantime, while the NN is training, we can explain the arguments within the model. Which will give us the following visualizations…. These visualizations display the Loss and Accuracy for both the Training and Validation set.

Use artificial intelligence to predict the value of Bitcoin

Otherwise, if our Loss and Accuracy from both sets are diverging from each other, then there may be a sign of overfitting from our NN. This might be solved by introducing some Dropout layers , reducing the number of epochs , altering the amount of layers , etc. This step in our NN training may require additional trials and tuning in order to observe the convergence of the Training and Validation set. Once the training is complete and we are satisfied with how the Loss and Accuracy converged. We will need to move on testing our model against actual data to see how well it performs.

When it comes to accurately predicting the price, our model falls short quite a few times.

Want to add to the discussion?

Although, the trend and potential price targets may provide some value. For example:. But, in actuality, the price reached slightly higher than that on day 6. From this example, the information may provide potential investment timing and opportunity to Bitcoin traders. When we are finally satisfied with validating our predicted Bitcoin values, then we can move on to the most useful part of our NN — forecasting the future prices of Bitcoin! To predict the next 10 days of Bitcoin prices, all we have to do is input the last 30 days worth of prices in our model.

With the following code we can print out the prices for the next 10 days as well as graph those predictions for better interpretability.