-1

I am using Keras on some data. Here are the details: 8,000 customers, each customer has varying time steps ranging from 2 - 41. So I am using zero padding to ensure all customers have 41 time steps. All 8,000 customers have 2 features and the data comes with multiclass labels, 0-4. Each tilmestep has a label.

After training the model, in the test part of the process I'd like to feed in the features and labels for timesteps 1-40, then have it predict the label in the 41st timestep. Does anyone know if this is possible? I've found Keras to be somewhat of a black box in interpreting what is it actually predicting (eg when it gives an accuracy score, what is this the accuracy of? What is it trying to predict: the last tilmestep label or all tilmestep labels?).

Is there a particular sub-division of model that should be used within sequential Keras LSTM models? I've read 'A many-to-one model (f(...)) produces one output (y(t)) value after receiving multiple input values (X(t), X(t+1), ...). ' (Brownlee 2017). However, it doesn't seem to make accommodation for the fact that my input is Xt & Yt for all time steps except the last one that I want to predict. I'm not sure how I would set up my code to instruct the model to predict the last timestep (that I have the data for but then I want to compare the predicted category with the actual category).

  • 1
    Which keras model are you using? – Spiff Nov 26 '19 at 09:12
  • I think many-to-one but I'm not sure how to programme the model to make it predict the last tilmestep, even though I have this data, to enable comparisons between the predicted value and the actual value (original question edited to provide more info). – Englishbeginner Nov 26 '19 at 14:25

1 Answers1

0

To predict the next timestep for each feature you would want your final Dense layer to be the same width as the number of features:

model.add(Dense(n_features))

There's a good example of a similar problem here under Multiple Parallel Series https://machinelearningmastery.com/how-to-develop-lstm-models-for-time-series-forecasting/

The accuracy is just a metric for measuring the effectiveness of your model. For accuracy, it's correct_predictions / total_predictions

https://keras.io/metrics/

Spiff
  • 614
  • 6
  • 16
  • I don’t want to predict feature values, I want to predict labels. Each time period has a vector of features (x) then the label for these features (y). I want to predict (y) for the next time period. I also have multiple sequences. The data relates to consumer behaviour. Each customer has a sequence of purchases over a number of different time periods. The y classification is the label related to these features at each time point for each customer. I want to predict what y will be for the customers next purchase. – Englishbeginner Nov 26 '19 at 17:23
  • Well in that case you'd want `model.add(Dense(n_labels))` instead. Then it would output the probability that the timestep belongs to the label for each label. – Spiff Nov 27 '19 at 09:22
  • Thanks SpiffyB - I'll give it a go and let you know how I get on. – Englishbeginner Nov 27 '19 at 15:32