How to feed a table per timestamp to LSTM neural network?
$begingroup$
I have a time-series dataframe like this
feat1 feat2 target
date id
0 1 12 16 192
2 15 6 90
3 2 9 18
1 1 0 3 0
2 0 9 0
3 56 9 504
2 1 5 9 45
2 6 9 54
3 5 8 40
and my problem is for regression.
What I know about the LSTM sequences, is that normally, the row_id is the date, so you build sequences of n rows.
In my data, as you can see, it's different. In each row that refers to the date, I have 3 more rows representing a product.
What I have thinked for make the sequence to my problem, my sequence will be of 2 days:
sequence = [day0,day1],[day1,day2]
For every date, I have
date0 = [id1,id2,id3].
For every id, I have:
id = [feat1,feat2].
the sequence[0], and it would be something like
[
[
[12,16],
[15,6],
[2,9]
],[
[0,3],
[0.9],
[56,9]
]
]
Is this valid?
Will the LSTM layer understand this? Or do I have to do some kind of extra transformation?
neural-network time-series lstm recurrent-neural-net
New contributor
Extermis is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
$endgroup$
add a comment |
$begingroup$
I have a time-series dataframe like this
feat1 feat2 target
date id
0 1 12 16 192
2 15 6 90
3 2 9 18
1 1 0 3 0
2 0 9 0
3 56 9 504
2 1 5 9 45
2 6 9 54
3 5 8 40
and my problem is for regression.
What I know about the LSTM sequences, is that normally, the row_id is the date, so you build sequences of n rows.
In my data, as you can see, it's different. In each row that refers to the date, I have 3 more rows representing a product.
What I have thinked for make the sequence to my problem, my sequence will be of 2 days:
sequence = [day0,day1],[day1,day2]
For every date, I have
date0 = [id1,id2,id3].
For every id, I have:
id = [feat1,feat2].
the sequence[0], and it would be something like
[
[
[12,16],
[15,6],
[2,9]
],[
[0,3],
[0.9],
[56,9]
]
]
Is this valid?
Will the LSTM layer understand this? Or do I have to do some kind of extra transformation?
neural-network time-series lstm recurrent-neural-net
New contributor
Extermis is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
$endgroup$
add a comment |
$begingroup$
I have a time-series dataframe like this
feat1 feat2 target
date id
0 1 12 16 192
2 15 6 90
3 2 9 18
1 1 0 3 0
2 0 9 0
3 56 9 504
2 1 5 9 45
2 6 9 54
3 5 8 40
and my problem is for regression.
What I know about the LSTM sequences, is that normally, the row_id is the date, so you build sequences of n rows.
In my data, as you can see, it's different. In each row that refers to the date, I have 3 more rows representing a product.
What I have thinked for make the sequence to my problem, my sequence will be of 2 days:
sequence = [day0,day1],[day1,day2]
For every date, I have
date0 = [id1,id2,id3].
For every id, I have:
id = [feat1,feat2].
the sequence[0], and it would be something like
[
[
[12,16],
[15,6],
[2,9]
],[
[0,3],
[0.9],
[56,9]
]
]
Is this valid?
Will the LSTM layer understand this? Or do I have to do some kind of extra transformation?
neural-network time-series lstm recurrent-neural-net
New contributor
Extermis is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
$endgroup$
I have a time-series dataframe like this
feat1 feat2 target
date id
0 1 12 16 192
2 15 6 90
3 2 9 18
1 1 0 3 0
2 0 9 0
3 56 9 504
2 1 5 9 45
2 6 9 54
3 5 8 40
and my problem is for regression.
What I know about the LSTM sequences, is that normally, the row_id is the date, so you build sequences of n rows.
In my data, as you can see, it's different. In each row that refers to the date, I have 3 more rows representing a product.
What I have thinked for make the sequence to my problem, my sequence will be of 2 days:
sequence = [day0,day1],[day1,day2]
For every date, I have
date0 = [id1,id2,id3].
For every id, I have:
id = [feat1,feat2].
the sequence[0], and it would be something like
[
[
[12,16],
[15,6],
[2,9]
],[
[0,3],
[0.9],
[56,9]
]
]
Is this valid?
Will the LSTM layer understand this? Or do I have to do some kind of extra transformation?
neural-network time-series lstm recurrent-neural-net
neural-network time-series lstm recurrent-neural-net
New contributor
Extermis is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
Extermis is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
edited 14 hours ago
Esmailian
3,311420
3,311420
New contributor
Extermis is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
asked 2 days ago
ExtermisExtermis
83
83
New contributor
Extermis is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
Extermis is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
Extermis is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
$begingroup$
Your data format is
feature1 feature2 target
product1 1 12 2
timestamp product2 2 6 3
product3 4 3 4
There are two designs for two assumptions:
Products are not related to each other. Therefore, each product could be modeled separately. That is, each timestamp is
X(t) = [feature1, feature2]or, including the target,X(t)|y(t) = [feature1, feature2, target]. And we build a model for each product separately. In summary, LSTM receives two 1 x 3 sequences fort-1andt, and outputs a 1 x 1 target fort + 1. In notation:
$$(overbrace{X_{t-1}|y_{t-1}}^{1 times 3}, overbrace{X_{t}|y_{t}}^{1 times 3}) rightarrow overbrace{y_{t+1}}^{1 times 1}$$
Products are related to each other, meaning
product1can helpproduct2to predict its target. For this, we just need to flatten the 3 x 2 matrix to a 1 x 6 vector, where the order of values does not matter. That is,
X(t) = [product1_feature1, product1_feature2, ..., product3_feature2]
or
X(t) = [product1_feature1, product2_feature1, ..., product3_feature2]
We can also add the targets, for example
X(t)|y(t) = [product1_feature1, product2_feature1, ..., product3_feature2, target1, ..., target3]
This way, dimension of each timestamp would be 9 (6 + 3), and a sequence of two timestamps would be
[
[product1_feature1, product2_feature1, ..., product3_feature2, target1, ..., target3], # t-1
[product1_feature1, product2_feature1, ..., product3_feature2, target1, ..., target3] # t
]
corresponding to a three dimensional target
[target1, ..., target3]att + 1.
In summary, LSTM receives two 1 x 9 sequences for
t-1andt, and outputs a 1 x 3 target fort + 1. In notation:
$$(overbrace{X_{t-1}|y_{t-1}}^{1 times 9}, overbrace{X_{t}|y_{t}}^{1 times 9}) rightarrow overbrace{y_{t+1}}^{1 times 3}$$
$endgroup$
$begingroup$
But I have 3 target on fact. [product1_feature1, product1_feature2,..., product3_feature2, target1,target2,target3] # each t
$endgroup$
– Extermis
2 days ago
$begingroup$
@Extermis my bad! updated.
$endgroup$
– Esmailian
2 days ago
add a comment |
Your Answer
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
});
}
});
Extermis 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%2f49236%2fhow-to-feed-a-table-per-timestamp-to-lstm-neural-network%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$
Your data format is
feature1 feature2 target
product1 1 12 2
timestamp product2 2 6 3
product3 4 3 4
There are two designs for two assumptions:
Products are not related to each other. Therefore, each product could be modeled separately. That is, each timestamp is
X(t) = [feature1, feature2]or, including the target,X(t)|y(t) = [feature1, feature2, target]. And we build a model for each product separately. In summary, LSTM receives two 1 x 3 sequences fort-1andt, and outputs a 1 x 1 target fort + 1. In notation:
$$(overbrace{X_{t-1}|y_{t-1}}^{1 times 3}, overbrace{X_{t}|y_{t}}^{1 times 3}) rightarrow overbrace{y_{t+1}}^{1 times 1}$$
Products are related to each other, meaning
product1can helpproduct2to predict its target. For this, we just need to flatten the 3 x 2 matrix to a 1 x 6 vector, where the order of values does not matter. That is,
X(t) = [product1_feature1, product1_feature2, ..., product3_feature2]
or
X(t) = [product1_feature1, product2_feature1, ..., product3_feature2]
We can also add the targets, for example
X(t)|y(t) = [product1_feature1, product2_feature1, ..., product3_feature2, target1, ..., target3]
This way, dimension of each timestamp would be 9 (6 + 3), and a sequence of two timestamps would be
[
[product1_feature1, product2_feature1, ..., product3_feature2, target1, ..., target3], # t-1
[product1_feature1, product2_feature1, ..., product3_feature2, target1, ..., target3] # t
]
corresponding to a three dimensional target
[target1, ..., target3]att + 1.
In summary, LSTM receives two 1 x 9 sequences for
t-1andt, and outputs a 1 x 3 target fort + 1. In notation:
$$(overbrace{X_{t-1}|y_{t-1}}^{1 times 9}, overbrace{X_{t}|y_{t}}^{1 times 9}) rightarrow overbrace{y_{t+1}}^{1 times 3}$$
$endgroup$
$begingroup$
But I have 3 target on fact. [product1_feature1, product1_feature2,..., product3_feature2, target1,target2,target3] # each t
$endgroup$
– Extermis
2 days ago
$begingroup$
@Extermis my bad! updated.
$endgroup$
– Esmailian
2 days ago
add a comment |
$begingroup$
Your data format is
feature1 feature2 target
product1 1 12 2
timestamp product2 2 6 3
product3 4 3 4
There are two designs for two assumptions:
Products are not related to each other. Therefore, each product could be modeled separately. That is, each timestamp is
X(t) = [feature1, feature2]or, including the target,X(t)|y(t) = [feature1, feature2, target]. And we build a model for each product separately. In summary, LSTM receives two 1 x 3 sequences fort-1andt, and outputs a 1 x 1 target fort + 1. In notation:
$$(overbrace{X_{t-1}|y_{t-1}}^{1 times 3}, overbrace{X_{t}|y_{t}}^{1 times 3}) rightarrow overbrace{y_{t+1}}^{1 times 1}$$
Products are related to each other, meaning
product1can helpproduct2to predict its target. For this, we just need to flatten the 3 x 2 matrix to a 1 x 6 vector, where the order of values does not matter. That is,
X(t) = [product1_feature1, product1_feature2, ..., product3_feature2]
or
X(t) = [product1_feature1, product2_feature1, ..., product3_feature2]
We can also add the targets, for example
X(t)|y(t) = [product1_feature1, product2_feature1, ..., product3_feature2, target1, ..., target3]
This way, dimension of each timestamp would be 9 (6 + 3), and a sequence of two timestamps would be
[
[product1_feature1, product2_feature1, ..., product3_feature2, target1, ..., target3], # t-1
[product1_feature1, product2_feature1, ..., product3_feature2, target1, ..., target3] # t
]
corresponding to a three dimensional target
[target1, ..., target3]att + 1.
In summary, LSTM receives two 1 x 9 sequences for
t-1andt, and outputs a 1 x 3 target fort + 1. In notation:
$$(overbrace{X_{t-1}|y_{t-1}}^{1 times 9}, overbrace{X_{t}|y_{t}}^{1 times 9}) rightarrow overbrace{y_{t+1}}^{1 times 3}$$
$endgroup$
$begingroup$
But I have 3 target on fact. [product1_feature1, product1_feature2,..., product3_feature2, target1,target2,target3] # each t
$endgroup$
– Extermis
2 days ago
$begingroup$
@Extermis my bad! updated.
$endgroup$
– Esmailian
2 days ago
add a comment |
$begingroup$
Your data format is
feature1 feature2 target
product1 1 12 2
timestamp product2 2 6 3
product3 4 3 4
There are two designs for two assumptions:
Products are not related to each other. Therefore, each product could be modeled separately. That is, each timestamp is
X(t) = [feature1, feature2]or, including the target,X(t)|y(t) = [feature1, feature2, target]. And we build a model for each product separately. In summary, LSTM receives two 1 x 3 sequences fort-1andt, and outputs a 1 x 1 target fort + 1. In notation:
$$(overbrace{X_{t-1}|y_{t-1}}^{1 times 3}, overbrace{X_{t}|y_{t}}^{1 times 3}) rightarrow overbrace{y_{t+1}}^{1 times 1}$$
Products are related to each other, meaning
product1can helpproduct2to predict its target. For this, we just need to flatten the 3 x 2 matrix to a 1 x 6 vector, where the order of values does not matter. That is,
X(t) = [product1_feature1, product1_feature2, ..., product3_feature2]
or
X(t) = [product1_feature1, product2_feature1, ..., product3_feature2]
We can also add the targets, for example
X(t)|y(t) = [product1_feature1, product2_feature1, ..., product3_feature2, target1, ..., target3]
This way, dimension of each timestamp would be 9 (6 + 3), and a sequence of two timestamps would be
[
[product1_feature1, product2_feature1, ..., product3_feature2, target1, ..., target3], # t-1
[product1_feature1, product2_feature1, ..., product3_feature2, target1, ..., target3] # t
]
corresponding to a three dimensional target
[target1, ..., target3]att + 1.
In summary, LSTM receives two 1 x 9 sequences for
t-1andt, and outputs a 1 x 3 target fort + 1. In notation:
$$(overbrace{X_{t-1}|y_{t-1}}^{1 times 9}, overbrace{X_{t}|y_{t}}^{1 times 9}) rightarrow overbrace{y_{t+1}}^{1 times 3}$$
$endgroup$
Your data format is
feature1 feature2 target
product1 1 12 2
timestamp product2 2 6 3
product3 4 3 4
There are two designs for two assumptions:
Products are not related to each other. Therefore, each product could be modeled separately. That is, each timestamp is
X(t) = [feature1, feature2]or, including the target,X(t)|y(t) = [feature1, feature2, target]. And we build a model for each product separately. In summary, LSTM receives two 1 x 3 sequences fort-1andt, and outputs a 1 x 1 target fort + 1. In notation:
$$(overbrace{X_{t-1}|y_{t-1}}^{1 times 3}, overbrace{X_{t}|y_{t}}^{1 times 3}) rightarrow overbrace{y_{t+1}}^{1 times 1}$$
Products are related to each other, meaning
product1can helpproduct2to predict its target. For this, we just need to flatten the 3 x 2 matrix to a 1 x 6 vector, where the order of values does not matter. That is,
X(t) = [product1_feature1, product1_feature2, ..., product3_feature2]
or
X(t) = [product1_feature1, product2_feature1, ..., product3_feature2]
We can also add the targets, for example
X(t)|y(t) = [product1_feature1, product2_feature1, ..., product3_feature2, target1, ..., target3]
This way, dimension of each timestamp would be 9 (6 + 3), and a sequence of two timestamps would be
[
[product1_feature1, product2_feature1, ..., product3_feature2, target1, ..., target3], # t-1
[product1_feature1, product2_feature1, ..., product3_feature2, target1, ..., target3] # t
]
corresponding to a three dimensional target
[target1, ..., target3]att + 1.
In summary, LSTM receives two 1 x 9 sequences for
t-1andt, and outputs a 1 x 3 target fort + 1. In notation:
$$(overbrace{X_{t-1}|y_{t-1}}^{1 times 9}, overbrace{X_{t}|y_{t}}^{1 times 9}) rightarrow overbrace{y_{t+1}}^{1 times 3}$$
edited 2 days ago
answered 2 days ago
EsmailianEsmailian
3,311420
3,311420
$begingroup$
But I have 3 target on fact. [product1_feature1, product1_feature2,..., product3_feature2, target1,target2,target3] # each t
$endgroup$
– Extermis
2 days ago
$begingroup$
@Extermis my bad! updated.
$endgroup$
– Esmailian
2 days ago
add a comment |
$begingroup$
But I have 3 target on fact. [product1_feature1, product1_feature2,..., product3_feature2, target1,target2,target3] # each t
$endgroup$
– Extermis
2 days ago
$begingroup$
@Extermis my bad! updated.
$endgroup$
– Esmailian
2 days ago
$begingroup$
But I have 3 target on fact. [product1_feature1, product1_feature2,..., product3_feature2, target1,target2,target3] # each t
$endgroup$
– Extermis
2 days ago
$begingroup$
But I have 3 target on fact. [product1_feature1, product1_feature2,..., product3_feature2, target1,target2,target3] # each t
$endgroup$
– Extermis
2 days ago
$begingroup$
@Extermis my bad! updated.
$endgroup$
– Esmailian
2 days ago
$begingroup$
@Extermis my bad! updated.
$endgroup$
– Esmailian
2 days ago
add a comment |
Extermis is a new contributor. Be nice, and check out our Code of Conduct.
Extermis is a new contributor. Be nice, and check out our Code of Conduct.
Extermis is a new contributor. Be nice, and check out our Code of Conduct.
Extermis 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%2f49236%2fhow-to-feed-a-table-per-timestamp-to-lstm-neural-network%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