I want to build an LSTM model for customer behaviour. It's the first time for me working on a timeseries, so some concepts are not clear to me at all.

My prediction problem is multidimensional, meaning that I also want to predict many informations associated to an action for each customer.

The dataset is currently shaped as a list of 2d padded arrays of one-hot encoded features (customer actions + other informations), for example:

   customer_id               encoded_features
0   25464205      [[0,1,0],..,[1,1,1],[1,0,1],..,[1,0,1]]
1   56456574      [[0,1,1],..,[1,0,1],[1,0,1],..,[1,1,1]]

where each element in the encoded_features entries represents a specific timestep.

My idea here is to use keras input shape

(n. customers, n. timesteps, length of features encoding)

In the example above it would be (2,#timesteps,3).

I have two main questions:

  1. Is this whole setting rigth for the prediction of next single customer action? I would like to simply give a new sequence of features for a certain customer and predict all features in the next timestep.

  2. I am thinking about splitting the data (according to a certain ratio) into sequential training and test sets, in order to test the trained model on unseen feature vectors. In the example above it would be:

  customer_id       X_train          y_train   
0   25464205       [[0,1,0],..]      [1,1,1]  
1   56456574       [[0,1,1],..]      [1,0,1] 

  customer_id       X_test           y_test    
0   25464205       [[1,0,1],..]      [1,0,1]
1   56456574       [[1,0,1],..]      [1,1,1]

Notice that X_train and X_test will generally contain all Train/Test events, except for the last one which has to be predicted. Is this a correct interpretation?

  • 1
    $\begingroup$ Test / Train split seems odd. For training, model will see just 1 record for each customer id. Is that what you intend to do ? $\endgroup$ – Shamit Verma Feb 20 '19 at 12:58
  • $\begingroup$ My fault, I just edited the question. I hope it's clearer now. $\endgroup$ – ginevracoal Feb 20 '19 at 13:18

This makes sense. It should work for input and first couple of layers. For output layers, you can have a softmax if you need to generate only next record in sequence.

Following Keras code has an example that :

  1. Accepts multi-dimensional inputs (Each sample is a Sequence of video frames)
  2. Predicts next few frames of video ( Multi dimensional since each pixel is a feature)


| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.