If you have machine learning skill why not apply that skill to predict cryptocurrency prices because everybody talking about cryptocurrency these days. In this tutorial, I’m going to show you how to predict the Bitcoin price, but this can apply to any cryptocurrency. We’re gonna use a very simple model built with Keras in TensorFlow.

The Keras is the easiest way to get started with Deep learning. It’s a great library. You can learn all about deep learning just from reading the Keras documentation.

In this tutorial, we’re gonna use bi-directional LSTM recurrent network. It’s basically a more advanced version of an RNN. That takes into account future values in sequence instead of just the past.

The dataset we are using is available at Bitcoin Historical Data. The first thing we do is importing all the necessary Python libraries.

For these first three lines is importing the relevant parts of Keras that we’re going to need for this model.

Data Processing


First, We are going to transform the data to get the average price grouped by the day and to see the usual DateTime format instead of timestamp.

Normalization

The reason we want to normalize data is that our model will be able to converge faster. The data normalization is a step that we always perform in data pre-processing.It‘s a very important thing to do.

For time-series transform, it’s going to be from a [number of days X the number of features] that were the original array. We are going to convert that to the number of days per sample times by the number of features so we’re turning it from 2D array to a 3D array and this is just a preprocessing step so we can then feed it into our network.

Buile Model


We are building a three-layer recurrent network with 20% dropout at each layer to reduce overfitting in the training. The type of RNN we’re going to build is called a bidirectional LSTM network.

Bi-directional LSTM RNN is a relatively complex model to make in TensorFlow but with Keras we can do this in just about 1 lines. The Dense fully connected layer comes at the end then our activation function and then our loss function at the very end which is going to be Adam.

The loss function is going to be mean squared error. The linear activation function in this model is going to determine the output of each neuron in the model.

Training the Model

We’re gonna train it with a batch size of 64 for 100 epochs. we are going to minimize the loss of its training data using the mean squared error. For fitting the model use model.fit and we give it all of those variables that we computed at the very beginning the training data.

Predict Price

Finally, we came to predicting the price and plot it to compare with the real results.

Rescale the predicted data to match its real values.
Predict bitcoin prices