title: How to predict a spike using neural network (preferably using neurolab or pybrain in python)
body: <p>I want to use neural networks to predict a timeseries B in the next 30 days from now based on a series A (I have the full history of series A), and a list of events E in the next 30 days (E is a list of binary units). Knowing that B is linearly proportional to A and when an event in day i happens (E[i] = 1), it triggers a spike on B (the ratio is unknown). I have training data containing tuples of (A, E, B). I have tested with feed forward network, but it doesn't perform very well (not predicting right spikes). Should I use recurrent networks and how can I do that neurolab or pybrain ? Thanks.</p>
  
  <p>You can have a look at an example <a href="http://i.imm.io/pHvc.png" rel="nofollow">here</a>.</p>
  
  <p>Edit: the code is a bit complicated, hence I can't paste here. However the idea is I feed A + E as inputs and predict B, so there are 30 + 30 input units, 30 output units, no hidden layer (I have tested with 1 hidden layer including 30 units and 90 units, but they don't perform better). The timeseries data is shown in the above link. (The red line is B, A is in similar shape without spikes).</p>
  
  <pre><code>A_list, B_list, E_list = input()
  X, Y = [A + E for A, E in zip(A_list, E_list)], B_list
  indim, outdim = len(X[0]), len(Y[0])
  network = nl.net.newp([[-1, 1]]*indim, outdim, transf=nl.trans.LogSig())    
  
  errors = network.train(norm_X(X),                                                        
                         norm_Y(Y),
                         epochs=4000, show=1000,
                         lr=0.01)
  </code></pre>
  
  <p>Where norm_X(X) scales X to [-1,1] and norm_Y scales Y to [0, 1].</p>