title: Neural Network to predict nth square
body: <p>I am trying to use multi-layer neural network to predict nth square.</p>
  
  <p>I have the following training data containing the first 99 squares</p>
  
  <pre><code>1    1
  2    4
  3    9
  4    16
  5    25
  ...
  98   9604
  99   9801
  </code></pre>
  
  <p>This is the code:</p>
  
  <pre><code>import numpy as np
  import neurolab as nl
  
  # Load input data
  text = np.loadtxt('data_sq.txt')
  
  # Separate it into datapoints and labels
  data = text[:, :1]
  labels = text[:, 1:]
  
  # Define a multilayer neural network with 2 hidden layers;
  # First hidden layer consists of 10 neurons
  # Second hidden layer consists of 6 neurons
  # Output layer consists of 1 neuron
  nn = nl.net.newff([[0, 99]], [10, 6, 1]) 
  
  # Train the neural network
  error_progress = nn.train(data, labels, epochs=2000, show=10, goal=0.01) 
  
  # Run the classifier on test datapoints
  print('\nTest results:')
  data_test = [[100], [101]]
  for item in data_test:
      print(item, '--&gt;', nn.sim([item])[0])
  </code></pre>
  
  <p>Which prints 1 for both 100th and 101st squares:</p>
  
  <pre><code>Test results:
  [100] --&gt; [ 1.]
  [101] --&gt; [ 1.]
  </code></pre>
  
  <p>What is the right way to do this?</p>