Keras LSTM model data reshapping












0















I have some Y-axis values of sine wave as features and I labeled it as pass or fail and used linear regression to train it and got 98% (since it is a synthetic data)
Now I tried to feed the data to a LSTM model and want to see the accuracy. But I don't know how to specify a LSTM model using my data.



I have Y = label =



array([[1, 0],[1, 0],[1, 0],[1, 0],[1, 0],[0, 1],[0, 1],[0, 1],[0, 1],[0, 1],[0, 1],[0, 1],[0, 1],[0, 1],[0, 1],[0, 1],[0, 1],[0, 1],[0, 1],[0, 1],...] with a shape(11564, 2).



and I have a feature = X =



array([[ 0., 0.03140919, 0.06278424, ..., -0.08864117,-0.0591398 , -0.02958302],[ 0., 0.03140762, 0.06277796, ..., -0.08349163,-0.05570133, -0.02786163],[ 0., 0.03140605, 0.06277169, ..., -0.07864125,-0.05246279, -0.02624041],...,[ 0. , 0.96491418, -0.5409955 , ..., 0. , 0. , 0. ],[ 0., 0.96496242, -0.5410496 , ..., 0. , 0. , 0. ],[ 0. , 0.96501067, -0.54110371, ..., 0. ,0. , 0.]]) with a shape of (11564, 1200))



Now how to I choose the values for the LSTM code:



model = Sequential()



model.add(keras.layers.LSTM(hidden_nodes, input_shape=(window, num_features)))



model.add(Dropout(0.2))



model.add(keras.layers.Dense(num_features, activation='sigmoid'))



optimizer = keras.optimizers.SGD(lr=learning_rate, decay=1e-6, momentum=0.9, nesterov=True)










share|improve this question



























    0















    I have some Y-axis values of sine wave as features and I labeled it as pass or fail and used linear regression to train it and got 98% (since it is a synthetic data)
    Now I tried to feed the data to a LSTM model and want to see the accuracy. But I don't know how to specify a LSTM model using my data.



    I have Y = label =



    array([[1, 0],[1, 0],[1, 0],[1, 0],[1, 0],[0, 1],[0, 1],[0, 1],[0, 1],[0, 1],[0, 1],[0, 1],[0, 1],[0, 1],[0, 1],[0, 1],[0, 1],[0, 1],[0, 1],[0, 1],...] with a shape(11564, 2).



    and I have a feature = X =



    array([[ 0., 0.03140919, 0.06278424, ..., -0.08864117,-0.0591398 , -0.02958302],[ 0., 0.03140762, 0.06277796, ..., -0.08349163,-0.05570133, -0.02786163],[ 0., 0.03140605, 0.06277169, ..., -0.07864125,-0.05246279, -0.02624041],...,[ 0. , 0.96491418, -0.5409955 , ..., 0. , 0. , 0. ],[ 0., 0.96496242, -0.5410496 , ..., 0. , 0. , 0. ],[ 0. , 0.96501067, -0.54110371, ..., 0. ,0. , 0.]]) with a shape of (11564, 1200))



    Now how to I choose the values for the LSTM code:



    model = Sequential()



    model.add(keras.layers.LSTM(hidden_nodes, input_shape=(window, num_features)))



    model.add(Dropout(0.2))



    model.add(keras.layers.Dense(num_features, activation='sigmoid'))



    optimizer = keras.optimizers.SGD(lr=learning_rate, decay=1e-6, momentum=0.9, nesterov=True)










    share|improve this question

























      0












      0








      0








      I have some Y-axis values of sine wave as features and I labeled it as pass or fail and used linear regression to train it and got 98% (since it is a synthetic data)
      Now I tried to feed the data to a LSTM model and want to see the accuracy. But I don't know how to specify a LSTM model using my data.



      I have Y = label =



      array([[1, 0],[1, 0],[1, 0],[1, 0],[1, 0],[0, 1],[0, 1],[0, 1],[0, 1],[0, 1],[0, 1],[0, 1],[0, 1],[0, 1],[0, 1],[0, 1],[0, 1],[0, 1],[0, 1],[0, 1],...] with a shape(11564, 2).



      and I have a feature = X =



      array([[ 0., 0.03140919, 0.06278424, ..., -0.08864117,-0.0591398 , -0.02958302],[ 0., 0.03140762, 0.06277796, ..., -0.08349163,-0.05570133, -0.02786163],[ 0., 0.03140605, 0.06277169, ..., -0.07864125,-0.05246279, -0.02624041],...,[ 0. , 0.96491418, -0.5409955 , ..., 0. , 0. , 0. ],[ 0., 0.96496242, -0.5410496 , ..., 0. , 0. , 0. ],[ 0. , 0.96501067, -0.54110371, ..., 0. ,0. , 0.]]) with a shape of (11564, 1200))



      Now how to I choose the values for the LSTM code:



      model = Sequential()



      model.add(keras.layers.LSTM(hidden_nodes, input_shape=(window, num_features)))



      model.add(Dropout(0.2))



      model.add(keras.layers.Dense(num_features, activation='sigmoid'))



      optimizer = keras.optimizers.SGD(lr=learning_rate, decay=1e-6, momentum=0.9, nesterov=True)










      share|improve this question














      I have some Y-axis values of sine wave as features and I labeled it as pass or fail and used linear regression to train it and got 98% (since it is a synthetic data)
      Now I tried to feed the data to a LSTM model and want to see the accuracy. But I don't know how to specify a LSTM model using my data.



      I have Y = label =



      array([[1, 0],[1, 0],[1, 0],[1, 0],[1, 0],[0, 1],[0, 1],[0, 1],[0, 1],[0, 1],[0, 1],[0, 1],[0, 1],[0, 1],[0, 1],[0, 1],[0, 1],[0, 1],[0, 1],[0, 1],...] with a shape(11564, 2).



      and I have a feature = X =



      array([[ 0., 0.03140919, 0.06278424, ..., -0.08864117,-0.0591398 , -0.02958302],[ 0., 0.03140762, 0.06277796, ..., -0.08349163,-0.05570133, -0.02786163],[ 0., 0.03140605, 0.06277169, ..., -0.07864125,-0.05246279, -0.02624041],...,[ 0. , 0.96491418, -0.5409955 , ..., 0. , 0. , 0. ],[ 0., 0.96496242, -0.5410496 , ..., 0. , 0. , 0. ],[ 0. , 0.96501067, -0.54110371, ..., 0. ,0. , 0.]]) with a shape of (11564, 1200))



      Now how to I choose the values for the LSTM code:



      model = Sequential()



      model.add(keras.layers.LSTM(hidden_nodes, input_shape=(window, num_features)))



      model.add(Dropout(0.2))



      model.add(keras.layers.Dense(num_features, activation='sigmoid'))



      optimizer = keras.optimizers.SGD(lr=learning_rate, decay=1e-6, momentum=0.9, nesterov=True)







      lstm






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 26 '18 at 2:26









      T.MouT.Mou

      1




      1
























          1 Answer
          1






          active

          oldest

          votes


















          0














          checklist:



          1 make sure your X, input is (11564,n) n is the number of length in each row, make sure n is the same in every row, if they are now ,please consider use the padding func



          2 seems u need a embedding layer or stuff like that to let lstm accept your data by, either shrink them to low degree, or reduce somehow




          keras.layers.LSTM(units, activation='tanh', recurrent_activation='hard_sigmoid', use_bias=True, kernel_initializer='glorot_uniform', recurrent_initializer='orthogonal', bias_initializer='zeros', unit_forget_bias=True, kernel_regularizer=None, recurrent_regularizer=None, bias_regularizer=None, activity_regularizer=None, kernel_constraint=None, recurrent_constraint=None, bias_constraint=None, dropout=0.0, recurrent_dropout=0.0, implementation=1, return_sequences=False, return_state=False, go_backwards=False, stateful=False, unroll=False)




          here is a example on kaggle:
          https://www.kaggle.com/divrikwicky/fast-basic-lstm-with-proper-k-fold-sentimentembed






          share|improve this answer
























          • for X all the n is same 1200. and this is not sentiment analysis, so do I need embedding?

            – T.Mou
            Nov 26 '18 at 21:45













          • i just mean, you need a way to fit the data format into the model, or u can try use just tensorflow to overwrite the data input format

            – 陈海栋
            Nov 27 '18 at 1:36











          • or u can add a pre-process to fit in the data

            – 陈海栋
            Nov 27 '18 at 1:49






          • 1





            Ok I got it. Thanks.

            – T.Mou
            Nov 27 '18 at 3:00











          • any chance u can vote or accept the answer?

            – 陈海栋
            Nov 27 '18 at 7:05











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          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: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          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
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53474025%2fkeras-lstm-model-data-reshapping%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









          0














          checklist:



          1 make sure your X, input is (11564,n) n is the number of length in each row, make sure n is the same in every row, if they are now ,please consider use the padding func



          2 seems u need a embedding layer or stuff like that to let lstm accept your data by, either shrink them to low degree, or reduce somehow




          keras.layers.LSTM(units, activation='tanh', recurrent_activation='hard_sigmoid', use_bias=True, kernel_initializer='glorot_uniform', recurrent_initializer='orthogonal', bias_initializer='zeros', unit_forget_bias=True, kernel_regularizer=None, recurrent_regularizer=None, bias_regularizer=None, activity_regularizer=None, kernel_constraint=None, recurrent_constraint=None, bias_constraint=None, dropout=0.0, recurrent_dropout=0.0, implementation=1, return_sequences=False, return_state=False, go_backwards=False, stateful=False, unroll=False)




          here is a example on kaggle:
          https://www.kaggle.com/divrikwicky/fast-basic-lstm-with-proper-k-fold-sentimentembed






          share|improve this answer
























          • for X all the n is same 1200. and this is not sentiment analysis, so do I need embedding?

            – T.Mou
            Nov 26 '18 at 21:45













          • i just mean, you need a way to fit the data format into the model, or u can try use just tensorflow to overwrite the data input format

            – 陈海栋
            Nov 27 '18 at 1:36











          • or u can add a pre-process to fit in the data

            – 陈海栋
            Nov 27 '18 at 1:49






          • 1





            Ok I got it. Thanks.

            – T.Mou
            Nov 27 '18 at 3:00











          • any chance u can vote or accept the answer?

            – 陈海栋
            Nov 27 '18 at 7:05
















          0














          checklist:



          1 make sure your X, input is (11564,n) n is the number of length in each row, make sure n is the same in every row, if they are now ,please consider use the padding func



          2 seems u need a embedding layer or stuff like that to let lstm accept your data by, either shrink them to low degree, or reduce somehow




          keras.layers.LSTM(units, activation='tanh', recurrent_activation='hard_sigmoid', use_bias=True, kernel_initializer='glorot_uniform', recurrent_initializer='orthogonal', bias_initializer='zeros', unit_forget_bias=True, kernel_regularizer=None, recurrent_regularizer=None, bias_regularizer=None, activity_regularizer=None, kernel_constraint=None, recurrent_constraint=None, bias_constraint=None, dropout=0.0, recurrent_dropout=0.0, implementation=1, return_sequences=False, return_state=False, go_backwards=False, stateful=False, unroll=False)




          here is a example on kaggle:
          https://www.kaggle.com/divrikwicky/fast-basic-lstm-with-proper-k-fold-sentimentembed






          share|improve this answer
























          • for X all the n is same 1200. and this is not sentiment analysis, so do I need embedding?

            – T.Mou
            Nov 26 '18 at 21:45













          • i just mean, you need a way to fit the data format into the model, or u can try use just tensorflow to overwrite the data input format

            – 陈海栋
            Nov 27 '18 at 1:36











          • or u can add a pre-process to fit in the data

            – 陈海栋
            Nov 27 '18 at 1:49






          • 1





            Ok I got it. Thanks.

            – T.Mou
            Nov 27 '18 at 3:00











          • any chance u can vote or accept the answer?

            – 陈海栋
            Nov 27 '18 at 7:05














          0












          0








          0







          checklist:



          1 make sure your X, input is (11564,n) n is the number of length in each row, make sure n is the same in every row, if they are now ,please consider use the padding func



          2 seems u need a embedding layer or stuff like that to let lstm accept your data by, either shrink them to low degree, or reduce somehow




          keras.layers.LSTM(units, activation='tanh', recurrent_activation='hard_sigmoid', use_bias=True, kernel_initializer='glorot_uniform', recurrent_initializer='orthogonal', bias_initializer='zeros', unit_forget_bias=True, kernel_regularizer=None, recurrent_regularizer=None, bias_regularizer=None, activity_regularizer=None, kernel_constraint=None, recurrent_constraint=None, bias_constraint=None, dropout=0.0, recurrent_dropout=0.0, implementation=1, return_sequences=False, return_state=False, go_backwards=False, stateful=False, unroll=False)




          here is a example on kaggle:
          https://www.kaggle.com/divrikwicky/fast-basic-lstm-with-proper-k-fold-sentimentembed






          share|improve this answer













          checklist:



          1 make sure your X, input is (11564,n) n is the number of length in each row, make sure n is the same in every row, if they are now ,please consider use the padding func



          2 seems u need a embedding layer or stuff like that to let lstm accept your data by, either shrink them to low degree, or reduce somehow




          keras.layers.LSTM(units, activation='tanh', recurrent_activation='hard_sigmoid', use_bias=True, kernel_initializer='glorot_uniform', recurrent_initializer='orthogonal', bias_initializer='zeros', unit_forget_bias=True, kernel_regularizer=None, recurrent_regularizer=None, bias_regularizer=None, activity_regularizer=None, kernel_constraint=None, recurrent_constraint=None, bias_constraint=None, dropout=0.0, recurrent_dropout=0.0, implementation=1, return_sequences=False, return_state=False, go_backwards=False, stateful=False, unroll=False)




          here is a example on kaggle:
          https://www.kaggle.com/divrikwicky/fast-basic-lstm-with-proper-k-fold-sentimentembed







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 26 '18 at 2:57









          陈海栋陈海栋

          504




          504













          • for X all the n is same 1200. and this is not sentiment analysis, so do I need embedding?

            – T.Mou
            Nov 26 '18 at 21:45













          • i just mean, you need a way to fit the data format into the model, or u can try use just tensorflow to overwrite the data input format

            – 陈海栋
            Nov 27 '18 at 1:36











          • or u can add a pre-process to fit in the data

            – 陈海栋
            Nov 27 '18 at 1:49






          • 1





            Ok I got it. Thanks.

            – T.Mou
            Nov 27 '18 at 3:00











          • any chance u can vote or accept the answer?

            – 陈海栋
            Nov 27 '18 at 7:05



















          • for X all the n is same 1200. and this is not sentiment analysis, so do I need embedding?

            – T.Mou
            Nov 26 '18 at 21:45













          • i just mean, you need a way to fit the data format into the model, or u can try use just tensorflow to overwrite the data input format

            – 陈海栋
            Nov 27 '18 at 1:36











          • or u can add a pre-process to fit in the data

            – 陈海栋
            Nov 27 '18 at 1:49






          • 1





            Ok I got it. Thanks.

            – T.Mou
            Nov 27 '18 at 3:00











          • any chance u can vote or accept the answer?

            – 陈海栋
            Nov 27 '18 at 7:05

















          for X all the n is same 1200. and this is not sentiment analysis, so do I need embedding?

          – T.Mou
          Nov 26 '18 at 21:45







          for X all the n is same 1200. and this is not sentiment analysis, so do I need embedding?

          – T.Mou
          Nov 26 '18 at 21:45















          i just mean, you need a way to fit the data format into the model, or u can try use just tensorflow to overwrite the data input format

          – 陈海栋
          Nov 27 '18 at 1:36





          i just mean, you need a way to fit the data format into the model, or u can try use just tensorflow to overwrite the data input format

          – 陈海栋
          Nov 27 '18 at 1:36













          or u can add a pre-process to fit in the data

          – 陈海栋
          Nov 27 '18 at 1:49





          or u can add a pre-process to fit in the data

          – 陈海栋
          Nov 27 '18 at 1:49




          1




          1





          Ok I got it. Thanks.

          – T.Mou
          Nov 27 '18 at 3:00





          Ok I got it. Thanks.

          – T.Mou
          Nov 27 '18 at 3:00













          any chance u can vote or accept the answer?

          – 陈海栋
          Nov 27 '18 at 7:05





          any chance u can vote or accept the answer?

          – 陈海栋
          Nov 27 '18 at 7:05




















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • 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.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53474025%2fkeras-lstm-model-data-reshapping%23new-answer', 'question_page');
          }
          );

          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







          Popular posts from this blog

          404 Error Contact Form 7 ajax form submitting

          How to know if a Active Directory user can login interactively

          TypeError: fit_transform() missing 1 required positional argument: 'X'