Back
12.10.2024
#Business
#DataScience
#Crypto

Are Cryptocurrencies predictable?

Graph of Bitcoins Price



Here is my jupyter notebook for the crypto price prediction challenge using kera’s LSTM. You can find the whole notebook including crypto data on my github: here.

Bimm Bimm Bamm Bamm. Lets begin by importing our Bitcoin price data: chosen_col variable can be changed above to alter what recorded price to use.

Data Table

Splitting our data into training set and test set:

Data Table

We see some pretty wild fluctuations at the end. Lets leave this as it is for now.

Continue by normalizing the values to floats between 0–1. We are using sklearn’s MinMaxScaler. We need to be careful to fit the scaler on our entire data range or else we will end up with a messed up scale between our test data and our train data. After we fit it we then transform both our test and training data.

Now we seperate our training data into our inputs and our outputs in time steps of time_steps. Where we will look at time_steps amount of data before we make our prediction of what the output for y will be.

Now we implement our actual model. We start with an LSTM input layer with 100 hidden units. We add a dropout of 0.2 before our Dense output layer with a linear activation and a shape of 1 (as we are outputting our expected price). We are using mean squared error to calculate our loss and adam as our optimizer.

Fit our model now on our X and y training/validation data. We take advantage of keras’ early stopping class so that once we are no longer recieving improvements the model will take its best weights and stop.

Data Table

Now we are breaking our testing data up into time steps and splitting it again into our inputs and our expected outputs. We then predict on the inputs and then scale both the inputs and outputs back up. Now we are ready to see how we did!

Another data Table

It looks ok!

You can see that the price climbed from 10k USD all the way up to 60k and back down to 35k. The largest problem I see with the predictions is that on the larger changes it lags a bit behind the actual prices. I assume this comes from the model still being innacurate when it comes to outrageous volatilitys like here.