T.Mou
T.Mou

Reputation: 71

Keras LSTM model data reshapping

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)

Upvotes: 0

Views: 111

Answers (1)

陈海栋
陈海栋

Reputation: 90

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

Upvotes: 0

Related Questions