LSTM Multi-state forecast
$begingroup$
I follow several tutorials about LSTM multi-step forecast to solve my problem.
My problem:
I have a time series of price about 3 months (Jan 2018 to Mar 2018) and I assume there are seasonal. So, my time series behaviors are changed because of such seasonal effects.
Q1
Do I need to apply sliding window to prevent learning from too long sequence. For example, each training sample takes prices of previous 14 days to predict the price of next 14 days. In other words, my input is (t-1), (t-2), ... , (t-7) and my output is (t), (t+1), ... , (t+6).
Q2
I read this post and feel that it's interesting by just passing a whole sequence and let the model makes decision by itself using the advantage of setting return_sequence=True
and stateful=True
. However, I'm a newbie to LSTM so I could not have clear understand how to apply it to the model according to such post.
Suppose my data look like this
import pandas as pd
import numpy as pd
np.random.seed(40)
df = pd.DataFrame({"Price":list(np.random.choice(range(1000, 1500), 14)) +
list(np.random.choice(range(1500, 2000), 14)) +
list(np.random.choice(range(1800, 2500), 14)) +
list(np.random.choice(range(1200, 1500), 14)) +
list(np.random.choice(range(1500, 2000), 14)) +
list(np.random.choice(range(1800, 2300), 14)) +
list(np.random.choice(range(2500, 3000), 14)) +
list(np.random.choice(range(2400, 2800), 14)) +
list(np.random.choice(range(2600, 3000), 14)) +
list(np.random.choice(range(2300, 2700), 14))},
index=pd.date_range(start="2018-03-25", periods=140))
df["Price"] = df["Price"].astype(float)
scaler = MinMaxScaler(feature_range=(0, 1))
df["Scaled"] = scaler.fit_transform(df["Price"].values.reshape(-1, 1))
If I configure my model as follows
from keras.models import Sequential
from keras.layers import Dense
from keras.layers import LSTM
model = Sequential()
model.add(LSTM(no_neuron, input_shape=(no_sample, timestep, no_feature)))
model.add(Dense(1))
model.compile(loss='mean_squared_error', optimizer='adam')
Is that make sense to set my timestep=40, no_sample=140, no_feature=1
for my problem? and How to define batch size?
Q3
In my settings, I really need to predict the price from Apr 2018 until Dec 2018 is that possible to do even I have only data from Jan 2018 to Mar 2018?
machine-learning deep-learning keras time-series lstm
New contributor
$endgroup$
add a comment |
$begingroup$
I follow several tutorials about LSTM multi-step forecast to solve my problem.
My problem:
I have a time series of price about 3 months (Jan 2018 to Mar 2018) and I assume there are seasonal. So, my time series behaviors are changed because of such seasonal effects.
Q1
Do I need to apply sliding window to prevent learning from too long sequence. For example, each training sample takes prices of previous 14 days to predict the price of next 14 days. In other words, my input is (t-1), (t-2), ... , (t-7) and my output is (t), (t+1), ... , (t+6).
Q2
I read this post and feel that it's interesting by just passing a whole sequence and let the model makes decision by itself using the advantage of setting return_sequence=True
and stateful=True
. However, I'm a newbie to LSTM so I could not have clear understand how to apply it to the model according to such post.
Suppose my data look like this
import pandas as pd
import numpy as pd
np.random.seed(40)
df = pd.DataFrame({"Price":list(np.random.choice(range(1000, 1500), 14)) +
list(np.random.choice(range(1500, 2000), 14)) +
list(np.random.choice(range(1800, 2500), 14)) +
list(np.random.choice(range(1200, 1500), 14)) +
list(np.random.choice(range(1500, 2000), 14)) +
list(np.random.choice(range(1800, 2300), 14)) +
list(np.random.choice(range(2500, 3000), 14)) +
list(np.random.choice(range(2400, 2800), 14)) +
list(np.random.choice(range(2600, 3000), 14)) +
list(np.random.choice(range(2300, 2700), 14))},
index=pd.date_range(start="2018-03-25", periods=140))
df["Price"] = df["Price"].astype(float)
scaler = MinMaxScaler(feature_range=(0, 1))
df["Scaled"] = scaler.fit_transform(df["Price"].values.reshape(-1, 1))
If I configure my model as follows
from keras.models import Sequential
from keras.layers import Dense
from keras.layers import LSTM
model = Sequential()
model.add(LSTM(no_neuron, input_shape=(no_sample, timestep, no_feature)))
model.add(Dense(1))
model.compile(loss='mean_squared_error', optimizer='adam')
Is that make sense to set my timestep=40, no_sample=140, no_feature=1
for my problem? and How to define batch size?
Q3
In my settings, I really need to predict the price from Apr 2018 until Dec 2018 is that possible to do even I have only data from Jan 2018 to Mar 2018?
machine-learning deep-learning keras time-series lstm
New contributor
$endgroup$
add a comment |
$begingroup$
I follow several tutorials about LSTM multi-step forecast to solve my problem.
My problem:
I have a time series of price about 3 months (Jan 2018 to Mar 2018) and I assume there are seasonal. So, my time series behaviors are changed because of such seasonal effects.
Q1
Do I need to apply sliding window to prevent learning from too long sequence. For example, each training sample takes prices of previous 14 days to predict the price of next 14 days. In other words, my input is (t-1), (t-2), ... , (t-7) and my output is (t), (t+1), ... , (t+6).
Q2
I read this post and feel that it's interesting by just passing a whole sequence and let the model makes decision by itself using the advantage of setting return_sequence=True
and stateful=True
. However, I'm a newbie to LSTM so I could not have clear understand how to apply it to the model according to such post.
Suppose my data look like this
import pandas as pd
import numpy as pd
np.random.seed(40)
df = pd.DataFrame({"Price":list(np.random.choice(range(1000, 1500), 14)) +
list(np.random.choice(range(1500, 2000), 14)) +
list(np.random.choice(range(1800, 2500), 14)) +
list(np.random.choice(range(1200, 1500), 14)) +
list(np.random.choice(range(1500, 2000), 14)) +
list(np.random.choice(range(1800, 2300), 14)) +
list(np.random.choice(range(2500, 3000), 14)) +
list(np.random.choice(range(2400, 2800), 14)) +
list(np.random.choice(range(2600, 3000), 14)) +
list(np.random.choice(range(2300, 2700), 14))},
index=pd.date_range(start="2018-03-25", periods=140))
df["Price"] = df["Price"].astype(float)
scaler = MinMaxScaler(feature_range=(0, 1))
df["Scaled"] = scaler.fit_transform(df["Price"].values.reshape(-1, 1))
If I configure my model as follows
from keras.models import Sequential
from keras.layers import Dense
from keras.layers import LSTM
model = Sequential()
model.add(LSTM(no_neuron, input_shape=(no_sample, timestep, no_feature)))
model.add(Dense(1))
model.compile(loss='mean_squared_error', optimizer='adam')
Is that make sense to set my timestep=40, no_sample=140, no_feature=1
for my problem? and How to define batch size?
Q3
In my settings, I really need to predict the price from Apr 2018 until Dec 2018 is that possible to do even I have only data from Jan 2018 to Mar 2018?
machine-learning deep-learning keras time-series lstm
New contributor
$endgroup$
I follow several tutorials about LSTM multi-step forecast to solve my problem.
My problem:
I have a time series of price about 3 months (Jan 2018 to Mar 2018) and I assume there are seasonal. So, my time series behaviors are changed because of such seasonal effects.
Q1
Do I need to apply sliding window to prevent learning from too long sequence. For example, each training sample takes prices of previous 14 days to predict the price of next 14 days. In other words, my input is (t-1), (t-2), ... , (t-7) and my output is (t), (t+1), ... , (t+6).
Q2
I read this post and feel that it's interesting by just passing a whole sequence and let the model makes decision by itself using the advantage of setting return_sequence=True
and stateful=True
. However, I'm a newbie to LSTM so I could not have clear understand how to apply it to the model according to such post.
Suppose my data look like this
import pandas as pd
import numpy as pd
np.random.seed(40)
df = pd.DataFrame({"Price":list(np.random.choice(range(1000, 1500), 14)) +
list(np.random.choice(range(1500, 2000), 14)) +
list(np.random.choice(range(1800, 2500), 14)) +
list(np.random.choice(range(1200, 1500), 14)) +
list(np.random.choice(range(1500, 2000), 14)) +
list(np.random.choice(range(1800, 2300), 14)) +
list(np.random.choice(range(2500, 3000), 14)) +
list(np.random.choice(range(2400, 2800), 14)) +
list(np.random.choice(range(2600, 3000), 14)) +
list(np.random.choice(range(2300, 2700), 14))},
index=pd.date_range(start="2018-03-25", periods=140))
df["Price"] = df["Price"].astype(float)
scaler = MinMaxScaler(feature_range=(0, 1))
df["Scaled"] = scaler.fit_transform(df["Price"].values.reshape(-1, 1))
If I configure my model as follows
from keras.models import Sequential
from keras.layers import Dense
from keras.layers import LSTM
model = Sequential()
model.add(LSTM(no_neuron, input_shape=(no_sample, timestep, no_feature)))
model.add(Dense(1))
model.compile(loss='mean_squared_error', optimizer='adam')
Is that make sense to set my timestep=40, no_sample=140, no_feature=1
for my problem? and How to define batch size?
Q3
In my settings, I really need to predict the price from Apr 2018 until Dec 2018 is that possible to do even I have only data from Jan 2018 to Mar 2018?
machine-learning deep-learning keras time-series lstm
machine-learning deep-learning keras time-series lstm
New contributor
New contributor
New contributor
asked 5 mins ago
Ratchainant ThammasudjaritRatchainant Thammasudjarit
101
101
New contributor
New contributor
add a comment |
add a comment |
0
active
oldest
votes
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
});
}
});
Ratchainant Thammasudjarit 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%2f45558%2flstm-multi-state-forecast%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Ratchainant Thammasudjarit is a new contributor. Be nice, and check out our Code of Conduct.
Ratchainant Thammasudjarit is a new contributor. Be nice, and check out our Code of Conduct.
Ratchainant Thammasudjarit is a new contributor. Be nice, and check out our Code of Conduct.
Ratchainant Thammasudjarit 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%2f45558%2flstm-multi-state-forecast%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