title: Need guidance on LSTM implementation in Keras
body: <p>I need help implementing a sequence classifier prediction using Keras APIs.</p>
  
  <p>So far, I've managed to get the data in a specific format that I believe should be suited for input into Keras, however, I am still failing to understand the exact specifics on what parameters I need to change.</p>
  
  <p>Here is the situation:</p>
  
  <p>What I have is a number of targets, with each target representing an independent event.</p>
  
  <p>Each target contains multiple detections of varying number. For example, one target might contain 33 detections, while another might contain 54. Each detection is just a single value between 0-1. The original dataset has a shape of <code>(# samples, # detections)</code>
  I want to be able to input the sequence of these detections into a LSTM to classify the overall target into two classes for ALL targets
  So far, I've pre-pended 0s to the detection sequences such that they are equal in length. Now the dataset has a shape of <code>(# samples, 77(max detections across all targets))</code></p>
  
  <p>Then, I create the time steps of an arbitrary window size of 7. The dataset has shape <code>(# samples, 77-window+1 = 71, 7)</code>. </p>
  
  <p>In case this isn't quite clear, the sequence has been turned from 1 long </p>
  
  <pre><code>[1, 2, 3, ... 77]
  </code></pre>
  
  <p>into 71 sequences of 7 that look like:</p>
  
  <pre><code>[[1, 2, 3, 4, 5, 6, 7], 
  [2, 3, 4, 5, 6, 7, 8], 
  ..., 
  [71, 72, 73, 74, 75, 76, 77]]
  </code></pre>
  
  <p>Now that my data is in the format <code>(# samples, # windows per sample, window)</code>, what tweaks should I make in order to obtain the output of 1 classification output per sample?</p>
  
  <p>I've tried looking online at keras's documentation about TimeDistributed layers and LSTM layers, at all of the blog posts on MachineLearningMastery, and other forum posts, but I couldn't quite understand enough for me to figure out how to use the API for my specific case.
  Here's what I have so far: </p>
  
  <pre><code>train_new.shape
  output: (31179, 71, 7)
  
  model = Sequential()
  model.add(LSTM(100, input_shape=(71, 7), return_sequences=True))
  model.add(TimeDistributed(Dense(1, activation='sigmoid')))
  model.compile(loss="binary_crossentropy", optimizer="adam", metrics=['accuracy'])
  
  model.fit(train_new, label_train, validation_data=(test, label_test), epochs=3, batch_size=128)
  
  Returns: 
  ValueError: Error when checking target: expected time_distributed_3 to have 3 dimensions, but got array with shape (31179, 1)
  </code></pre>
  
  <p>Any direction or guidance would be greatly appreciated.</p>
  
  <p>Thanks for your time!</p>