tensorflowmachine-learningneural-networklstmmultivariate-time-series

LSTM multivariate predicting multiple features


I am new to this neural networks and LSTM. I hope I will get a guidance from you and I will be thankful to you.

I have 2 years of bitcoin historical dataset and bitcoin sentiment dataset which is of one hour interval. My goal is to predict next 60 hours future chart using LSTM.

I have seen some of the articles regarding multivariate time series prediction. But in all of them they are taking only one feature for prediction. They predict only the price of one upcoming day and . So in order to predict next 2 months data, I have to predict all of the features. So that I can seed the predicted data as input for the next prediction and so on to predict for next 60 days. Can someone help me to figure out how can I do this kind of prediction?

Edit: The dataset looks like this:

timestamp,close,sentiment
2020-05-01_00,8842.85,0.21
2020-05-01_01,8824.43,0.2
2020-05-01_02,8745.91,0.2
2020-05-01_03,8639.12,0.19
2020-05-01_04,8625.69,0.2

And I would like to use tenserflow as backend. As of now i have not written code for building the model as I have to know what to do before i start coding.

The idea is to give 100 or 150 rows of data as input to the model and then forecast for the next 60 hours by seeding the prediction of the model as the input for the next prediction.


Solution

  • It would help if you shared some code for how you are constructing your model, and what your data looks like. How is your sentiment data encoded, and what framework you are using (tensorflow, pytorch, etc)? I am mostly familiar with Tensorflow, so I'll point you in that direction.

    In general it can be helpful to use an Input Layer, but LSTMs expect a 3D tensor
    [batch, timestamps, feature].

    You might want to consider a non-sequential model architecture, using functional APIs. If you went that route, you could have 2 separate inputs. One being the price time series, the other being the sentiment time series pass each to an LSTM then you can concatenate/combine them and pass them to Dense layers or even convolutional layers.

    Lastly you could also look into ConvLSTM2D which takes a 5D tensor:
    [samples, time, channels, rows, cols]

    #------------------ Response (👇) post update: -------------------------
    View the notebook here

    #===========Design Model Architecture:
    #==== Create Input Layers:
    Price_Input = tf.keras.layers.Input(shape=(60,),name='Price_Input')                       #Price as Input
    Sent_Input = tf.keras.layers.Input(shape=(60,),name='Sentiment_Input')                    #Sentiment as Input
    
    #=== Handle Reshaping as part of the Model Architecture:
    P_Input_rshp = tf.keras.layers.Reshape(target_shape=(60,1),
                                           input_shape=(60,),
                                           name='Price_Reshape')(Price_Input)                 #Pass price to reshape layer
    
    S_Input_rshp = tf.keras.layers.Reshape(target_shape=(60,1),
                                           input_shape=(60,),
                                           name='Sentiment_Reshape')(Sent_Input)              #Pass sentiment to rehape layer
    
    #=== Use LSTM layers for timeseries:
    P_x = tf.keras.layers.LSTM(units=1,activation='tanh',name='Price_LSTM')(P_Input_rshp)     #Price Focused LSTM
    S_x = tf.keras.layers.LSTM(units=1,activation='tanh',name='Sentiment_LSTM')(S_Input_rshp) #Sentiment Focused LSTM
    
    C_x = tf.keras.layers.Concatenate(name='Concat')([P_x,S_x])                               #Concatinate(join) inputs from each branch
    
    Output = tf.keras.layers.Dense(units=1,name='Dense')(C_x)                                 #Dense layer as model output to synthesize results
    
    
    #============== Greate Model Graph:
    model = tf.keras.Model(inputs=[Price_Input,Sent_Input],
                           outputs=Output,
                           name='Double_LSTM_Model')