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.
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))