Input shape

Keras expects the input for our LSTM to be a three-dimensional tensor that looks like:

The first dimension is obviously the number of observations we have, and we would expect that.

The second dimension corresponds to the number of lags we've chosen when using the lag_dataframe function. This is the number of time steps we're going to give Keras in order to make a prediction.

The third dimension is the number of features present in that time step. In our example, we'll be using one, because we only have one feature per time step, that time step's bitcoin price.

Before reading on, consider carefully the power that defining a three dimensional matrix here gives you. We absolutely could include hundreds of other time series as features to predict this time series. In doing so, and in using an LSTM, we get feature engineering between those features for free. It's this functionality that makes LSTMs so exciting in the financial domains.

For the problem at hand, we will need to convert our two-dimensional matrix into a three-dimensional matrix. To do so we will use NumPy's handy reshape function, as shown in the following code:

X_train = np.reshape(X_train.values, (X_train.shape[0], X_train.shape[1], 1))
X_test = np.reshape(X_test.values, (X_test.shape[0], X_test.shape[1], 1))
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.15.12.34