{"action":"created","issue":{"url":"https://api.github.com/repos/fchollet/keras/issues/7241","repository_url":"https://api.github.com/repos/fchollet/keras","labels_url":"https://api.github.com/repos/fchollet/keras/issues/7241/labels{/name}","comments_url":"https://api.github.com/repos/fchollet/keras/issues/7241/comments","events_url":"https://api.github.com/repos/fchollet/keras/issues/7241/events","html_url":"https://github.com/fchollet/keras/issues/7241","id":240658780,"number":7241,"title":"Need to clarify the shape of input data and the structure of the LSTM network","user":{"login":"paba","id":1038418,"avatar_url":"https://avatars3.githubusercontent.com/u/1038418?v=3","gravatar_id":"","url":"https://api.github.com/users/paba","html_url":"https://github.com/paba","followers_url":"https://api.github.com/users/paba/followers","following_url":"https://api.github.com/users/paba/following{/other_user}","gists_url":"https://api.github.com/users/paba/gists{/gist_id}","starred_url":"https://api.github.com/users/paba/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/paba/subscriptions","organizations_url":"https://api.github.com/users/paba/orgs","repos_url":"https://api.github.com/users/paba/repos","events_url":"https://api.github.com/users/paba/events{/privacy}","received_events_url":"https://api.github.com/users/paba/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2017-07-05T13:55:01Z","updated_at":"2017-07-05T14:10:24Z","closed_at":null,"body":"I recently started working with keras to build a LSTM model. \r\nI find it difficult to understand the shape of the input data that we provide to batch_input_shape and the exact structure of the LSTM model that results. \r\nHere is my problem: I am trying to do time series model of revenue. My training dataset, X, has the shape 803,7 -- 803 samples and 7 features (these seven features are the lagged values of the revenue ). \r\n\r\nI reshaped this input as: \r\nX = X.reshape(X.shape[0], 1, X.shape[1])\r\n\r\nNow the new shape of my input is 803, 1, 7\r\n\r\nI created the model as follows:\r\nmodel = Sequential()\r\nneurons = 4\r\nmodel.add(LSTM(neurons, batch_input_shape=(1, X.shape[1], X.shape[2]), stateful=True, return_sequences=True ) ) \r\nmodel.add(Dense(1))\r\n\r\nI have three questions. \r\n1) Does the model created by the above code look like this?\r\n\r\n\r\n  \r\n\r\n```\r\n y_t0     y_t1      y_t2\r\n    |             |            |\r\n LSTM -> LSTM ->LSTM --------\r\n    |            |            |\r\nX_t0      X_t1       X_t2\r\n```\r\n\r\n\r\nwhere X_tn = [ feature1, feature2, feature3, feature4, feature5, feature6, feature7] \r\n\r\n2) How shouldI shape the data/ what input should I provide if I want a many to one model like this\r\n```\r\n\r\n                                                                                       Y\r\n                                                                                        |\r\nLSTM -> LSTM ->LSTM ->LSTM ->LSTM ->LSTM ->LSTM\r\n    |          |            |            |              |             |             |\r\nX_t0     X_t1       X_t2     X_t3       X_t4      X_t5       X_t6\r\n```\r\n\r\n\r\n3) What does the batch size exactly mean? \r\n\r\nThe Keras document did not give me a clear understanding. \r\nThank you very much. \r\n \r\n  \r\n"},"comment":{"url":"https://api.github.com/repos/fchollet/keras/issues/comments/313114353","html_url":"https://github.com/fchollet/keras/issues/7241#issuecomment-313114353","issue_url":"https://api.github.com/repos/fchollet/keras/issues/7241","id":313114353,"user":{"login":"td2014","id":3465912,"avatar_url":"https://avatars3.githubusercontent.com/u/3465912?v=3","gravatar_id":"","url":"https://api.github.com/users/td2014","html_url":"https://github.com/td2014","followers_url":"https://api.github.com/users/td2014/followers","following_url":"https://api.github.com/users/td2014/following{/other_user}","gists_url":"https://api.github.com/users/td2014/gists{/gist_id}","starred_url":"https://api.github.com/users/td2014/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/td2014/subscriptions","organizations_url":"https://api.github.com/users/td2014/orgs","repos_url":"https://api.github.com/users/td2014/repos","events_url":"https://api.github.com/users/td2014/events{/privacy}","received_events_url":"https://api.github.com/users/td2014/received_events","type":"User","site_admin":false},"created_at":"2017-07-05T14:10:24Z","updated_at":"2017-07-05T14:10:24Z","body":"@paba   Regarding your third question, the Keras FAQ section:  https://keras.io/getting-started/faq/#what-does-sample-batch-epoch-mean \r\nhas a good description of the meaning of the terms, and you might find that helpful.  Basically, the batch dimension represents the data samples.  In your case, the batch (sample) dimension is of length 803.  Note that typically, you don't specify the size of the batch dimension in the argument list of the layers.  The input shape would only specify the dimensions of the data of the sample itself.  For example, I think you are trying to provide 7 timesteps of scalar data per sample.  So, your input shape would be (7,1).  I hope this helps.  "}}
{"actor":{"display_login":"td2014"}}