title: Predicting time series data with Neural Network in python
body: <p>I'm a beginner in Neural Network and trying to predict values which are temperature values(output) with 5 inputs in python. I used <strong>keras package</strong> in python to work Neural Network.</p>
  
  <p>Also, I used two algorithms which are feedforward Neural Network(Regression) and Recurrent Neural Network(LSTM) to predict values. However, both of algorithms didn't work well for forecasting.</p>
  
  <p>In my case of Feedforward Neural Network(Regression), I used 3 hidden layers(with 100, 200, 300 neurons) like code below,</p>
  
  <pre><code>def baseline_model():
      # create model
      model = Sequential()
      model.add(Dense(100, input_dim=5, kernel_initializer='normal', activation='sigmoid'))
      model.add(Dense(200, kernel_initializer = 'normal', activation='sigmoid'))
      model.add(Dense(300, kernel_initializer = 'normal', activation='sigmoid'))
      model.add(Dense(1, kernel_initializer='normal'))
      # Compile model
      model.compile(loss='mean_squared_error', optimizer='adam')
      return model
  
  
  df = DataFrame({'Time': TIME_list, 'input1': input1_list, 'input2': input2_list, 'input3': input3_list, 'input4': input4_list, 'input5': input5_list, 'output': output_list})
  df.index = pd.to_datetime(df.Time)
  df = df.values
  
  #Setting training data and test data
  train_size_x = int(len(df)*0.8)     #The user can change the range of training data
  print(train_size_x)
  X_train = df[0:train_size_x, 0:5]
  t_train = df[0:train_size_x, 6]
  X_test = df[train_size_x:int(len(df)), 0:5]
  t_test = df[train_size_x:int(len(df)), 6]
  
  # fix random seed for reproducibility
  seed = 7
  np.random.seed(seed)
  
  scale = StandardScaler()
  X_train = scale.fit_transform(X_train)
  X_test = scale.transform(X_test)
  
  #Regression in Keras package
  clf = KerasRegressor(build_fn=baseline_model, nb_epoch=50, batch_size=5, verbose=0)
  
  clf.fit(X_train,t_train)
  res = clf.predict(X_test)
  </code></pre>
  
  <p>However, the error was quite big. The maximum absolute error was 78.4834. So I tried to minimize that error by changing number of hidden layer or neurons in hidden layer, but the error stayed around same.</p>
  
  <p>After feedforward NN, secondly, I used Recurrent Neural Network(LSTM) algorithm which can predict by using only one input. In my case, the input is temperature. It gives me much less error than the feedforward NN, but I was lost in deep thought that Recurrent Nueral Network(LSTM) I implemented is little ambiguous in my case because it didn't use 5 inputs that affect the output(temperature value) such as feedforward regression that I implemented above.</p>
  
  <p>And now I got lost what other kinds of algorithm I should use.</p>
  
  <p>Any suggestions or ideas for my case..?</p>
  
  <p>Thanks in advance.</p>