Skip to main content
deleted 847 characters in body
Source Link
almo
  • 161
  • 10

Comments:

I can't give my comment to @gunes now. It's locked. So I would ask here:

  1. Can also this kind of multilabel dataset treated as time series. BTW, this is bioinformatic data

  2. I read this blog(see the middle part) when I tried to write my model and its code like this:

    model = Sequential() model.add(LSTM(4, input_shape=(1, look_back))) model.add(Dense(1)) model.compile(loss='mean_squared_error', optimizer='adam') model.fit(trainX, trainY, epochs=100, batch_size=1, verbose=2)

Is this the same as tf.keras.layers.LSTM? To simplify, if I would like to use model the same as model in the that blog, the parameters should be (40,626,1) or (40,1,626). This is really confusing. As I 've seen many people did totally different way. Sorry for asking such a long question.

Comments:

I can't give my comment to @gunes now. It's locked. So I would ask here:

  1. Can also this kind of multilabel dataset treated as time series. BTW, this is bioinformatic data

  2. I read this blog(see the middle part) when I tried to write my model and its code like this:

    model = Sequential() model.add(LSTM(4, input_shape=(1, look_back))) model.add(Dense(1)) model.compile(loss='mean_squared_error', optimizer='adam') model.fit(trainX, trainY, epochs=100, batch_size=1, verbose=2)

Is this the same as tf.keras.layers.LSTM? To simplify, if I would like to use model the same as model in the that blog, the parameters should be (40,626,1) or (40,1,626). This is really confusing. As I 've seen many people did totally different way. Sorry for asking such a long question.

added 956 characters in body
Source Link
almo
  • 161
  • 10

Comments:

I can't give my comment to @gunes now. It's locked. So I would ask here:

  1. Can also this kind of multilabel dataset treated as time series. BTW, this is bioinformatic data

  2. I read this blog(see the middle part) when I tried to write my model and its code like this:

    model = Sequential() model.add(LSTM(4, input_shape=(1, look_back))) model.add(Dense(1)) model.compile(loss='mean_squared_error', optimizer='adam') model.fit(trainX, trainY, epochs=100, batch_size=1, verbose=2)

Is this the same as tf.keras.layers.LSTM? To simplify, if I would like to use model the same as model in the that blog, the parameters should be (40,626,1) or (40,1,626). This is really confusing. As I 've seen many people did totally different way. Sorry for asking such a long question.

Comments:

I can't give my comment to @gunes now. It's locked. So I would ask here:

  1. Can also this kind of multilabel dataset treated as time series. BTW, this is bioinformatic data

  2. I read this blog(see the middle part) when I tried to write my model and its code like this:

    model = Sequential() model.add(LSTM(4, input_shape=(1, look_back))) model.add(Dense(1)) model.compile(loss='mean_squared_error', optimizer='adam') model.fit(trainX, trainY, epochs=100, batch_size=1, verbose=2)

Is this the same as tf.keras.layers.LSTM? To simplify, if I would like to use model the same as model in the that blog, the parameters should be (40,626,1) or (40,1,626). This is really confusing. As I 've seen many people did totally different way. Sorry for asking such a long question.

Source Link
almo
  • 161
  • 10

LSTM input and output parameter (not time series, not NLP)

I have asked this question on stackoverflow but nobody answers. So I come here in the hope that somebody could help me solve it. Thank you! Here is my question:

I am a little bit confusing about how should I set parameters in my Keras LSTM model. The dataset is like this:

 print(x_train.shape, y_train.shape)
 (1000, 626) (1000, 225) #This is a multilabel dataset. Each label has two possibilities either 0 or 1.

I checked Keras document, it says like this:

hidden_units, time steps, input dimension 

So should I set it as:

model.add(LSTM(40, activation='relu', input_shape=(626, 1)))

or

 model.add(LSTM(40, activation='relu', input_shape=(1,626)))

Note, the hidden units is calculated=40, but then it's smaller than both input and output dimensions. See the following tables:

Tabel one: set input as hidden_units=40, input_shape=(1,626)

 Model: "sequential_1"
 _________________________________________________________________
 Layer (type)                 Output Shape              Param #   
 =================================================================
 LSTM_1 (LSTM)                (None, 1, 40)             106720    
 _________________________________________________________________
 LSTM_2 (LSTM)                (None, 1, 20)             4880      
 _________________________________________________________________
 Dense_1 (Dense)              (None, 1, 250)            5250      
 _________________________________________________________________
 Dense_2 (Dense)              (None, 1, 225)            51706     
 =================================================================
 Total params: 168,556
 Trainable params: 168,556
 Non-trainable params: 0
 _________________________________________________________________

Tabel two: Set hidden_units=40, input_shape=(626,1)

  Model: "sequential_2"
  _________________________________________________________________
  Layer (type)                 Output Shape              Param #   
  =================================================================
  LSTM_1 (LSTM)                (None, 626, 40)           6720      
  _________________________________________________________________
  LSTM_2 (LSTM)                (None, 626, 20)           4880      
  _________________________________________________________________
  Dense_1 (Dense)              (None, 626, 250)          5250      
  _________________________________________________________________
  Dense_2 (Dense)              (None, 626, 225)          56475     
  =================================================================
  Total params: 73,325
  Trainable params: 73,325
  Non-trainable params: 0
  _________________________________________________________________

In both bases, the output is set based on the dimension of output shape. I 've seen on stackoverflow people have different answers. e.g. this and this

So in this case what is the right way to set those parameters (hidden_units, input_shapes) and output_shapes

Thanks of your help!