We’ll frame our problem as follows. We have historical price data for Bitcoin, which…
- User
We’ll frame our problem as follows. We have historical price data for Bitcoin, which includes the following predictors for each day (where we have daily time steps):
Opening price High price Low price Volume traded Our goal is to take some sequence of the above four values (say, for 100 previous days), and predict the target variable (Bitcoin’s price) for the next 50 days into the future. Consequently, we need a way to feed in these multiple values at each time step to our LSTM using Google Colab with our csv file located in goodle drive with the csv link in https://drive.google.com/file/d/1J_0IgW_Ef6acETKT5r87J2aaX8Iy-OuS/view?usp=share_link , and to produce a singular output representing the prediction at the next time step in return. In this way, we construct a multivariate LSTM. then we clean the data by removing adjusted close from the csv:
df = pd.read_csv('BTC-USD.csv', index_col = 'Date', parse_dates=True) df.drop(columns=['Adj Close'], inplace=True) df.head(5)
from now on you will refeer to historical prices csv as: https://drive.google.com/file/d/1J_0IgW_Ef6acETKT5r87J2aaX8Iy-OuS/view?usp=share_link.
At the bare minimum, your exploratory data analysis should consist of plotting the target variable of interest. Let’s plot the Bitcoin price over time to see what we’re actually trying to predict.
plt.plot(df.Close) plt.xlabel("Time") plt.ylabel("Price (USD)") plt.title("Bitcoin price over time") plt.savefig("initial_plot.png", dpi=250) plt.show();
We want a realistic emulation of what would happen in the real-world. That is, we want a few years of historical data, and train an LSTM to predict what will happen to the price of Bitcoin in the next few months.
Setting inputs and outputs Recall that our predictors will consist of all the columns except our target, closing price. Note that we want to use an sklearn preprocessor below, which requires reshaping the array if it consists of a single feature, as our target does. Hence, for the target y, we have to call values, which removes the axes labels and will allow us to reshape the array.
X, y = df.drop(columns=['Close']), df.Close.values X.shape, y.shape
((5438, 4), (5438,))
We’ll use standardisation for our training features X by removing the mean and scaling to unit variance. Standardisation helps the deep learning model to learn by ensuring that parameters can exist in the same multi-dimensional space; it wouldn’t make much sense to have the weights have to change their size simply because all the variables have different scales. For our target y, we will scale and translate each feature individually to between 0 and 1. This transformation is often used as an alternative to zero mean, unit variance scaling:
- Assistant
Now that we have prepared our data and split it into training and testing sets, we can create our LSTM model using Google Colab.
Begin by importing the necessary libraries: