How to reshape data for LSTM training in multivariate sequence prediction
$begingroup$
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:
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.
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?
python keras time-series lstm recurrent-neural-net
New contributor
$endgroup$
add a comment |
$begingroup$
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:
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.
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?
python keras time-series lstm recurrent-neural-net
New contributor
$endgroup$
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
yesterday
$begingroup$
My fault, I just edited the question. I hope it's clearer now.
$endgroup$
– ginevracoal
yesterday
add a comment |
$begingroup$
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:
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.
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?
python keras time-series lstm recurrent-neural-net
New contributor
$endgroup$
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:
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.
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?
python keras time-series lstm recurrent-neural-net
python keras time-series lstm recurrent-neural-net
New contributor
New contributor
edited yesterday
ginevracoal
New contributor
asked yesterday
ginevracoalginevracoal
1085
1085
New contributor
New contributor
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
yesterday
$begingroup$
My fault, I just edited the question. I hope it's clearer now.
$endgroup$
– ginevracoal
yesterday
add a comment |
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
yesterday
$begingroup$
My fault, I just edited the question. I hope it's clearer now.
$endgroup$
– ginevracoal
yesterday
1
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
yesterday
$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
yesterday
$begingroup$
My fault, I just edited the question. I hope it's clearer now.
$endgroup$
– ginevracoal
yesterday
$begingroup$
My fault, I just edited the question. I hope it's clearer now.
$endgroup$
– ginevracoal
yesterday
add a comment |
1 Answer
1
active
oldest
votes
$begingroup$
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 :
- Accepts multi-dimensional inputs (Each sample is a Sequence of video frames)
- Predicts next few frames of video ( Multi dimensional since each pixel is a feature)
https://github.com/keras-team/keras/blob/master/examples/conv_lstm.py
$endgroup$
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
return StackExchange.using("mathjaxEditing", function () {
StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix) {
StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["$", "$"], ["\\(","\\)"]]);
});
});
}, "mathjax-editing");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "557"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
ginevracoal is a new contributor. Be nice, and check out our Code of Conduct.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fdatascience.stackexchange.com%2fquestions%2f45867%2fhow-to-reshape-data-for-lstm-training-in-multivariate-sequence-prediction%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
$begingroup$
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 :
- Accepts multi-dimensional inputs (Each sample is a Sequence of video frames)
- Predicts next few frames of video ( Multi dimensional since each pixel is a feature)
https://github.com/keras-team/keras/blob/master/examples/conv_lstm.py
$endgroup$
add a comment |
$begingroup$
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 :
- Accepts multi-dimensional inputs (Each sample is a Sequence of video frames)
- Predicts next few frames of video ( Multi dimensional since each pixel is a feature)
https://github.com/keras-team/keras/blob/master/examples/conv_lstm.py
$endgroup$
add a comment |
$begingroup$
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 :
- Accepts multi-dimensional inputs (Each sample is a Sequence of video frames)
- Predicts next few frames of video ( Multi dimensional since each pixel is a feature)
https://github.com/keras-team/keras/blob/master/examples/conv_lstm.py
$endgroup$
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 :
- Accepts multi-dimensional inputs (Each sample is a Sequence of video frames)
- Predicts next few frames of video ( Multi dimensional since each pixel is a feature)
https://github.com/keras-team/keras/blob/master/examples/conv_lstm.py
answered yesterday
Shamit VermaShamit Verma
57516
57516
add a comment |
add a comment |
ginevracoal is a new contributor. Be nice, and check out our Code of Conduct.
ginevracoal is a new contributor. Be nice, and check out our Code of Conduct.
ginevracoal is a new contributor. Be nice, and check out our Code of Conduct.
ginevracoal is a new contributor. Be nice, and check out our Code of Conduct.
Thanks for contributing an answer to Data Science Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
Use MathJax to format equations. MathJax reference.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fdatascience.stackexchange.com%2fquestions%2f45867%2fhow-to-reshape-data-for-lstm-training-in-multivariate-sequence-prediction%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
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
yesterday
$begingroup$
My fault, I just edited the question. I hope it's clearer now.
$endgroup$
– ginevracoal
yesterday