title: Neuron results are a little off
body: <p>Hi I coded a single neuron to predict a student's mark for subject D based of the marks they got for subject A, B and C.</p>
  
  <p>After training my neuron with some historical data that contain the 3 marks as well as the actual mark they got for subject D, I then inputed test data to see how closely the predicted mark would match with the actual one.
  Below is my Neuron class</p>
  
  <pre><code>public class Neuron
  {
      double[] Weights = new double[3];
  
      public Neuron(double W1, double W2, double W3)
      {
          Weights[0] = W1;
          Weights[1] = W2;
          Weights[2] = W3;
      }
  
      public double FnetLinear(int Z1, int Z2, int Z3)
      {
          return (Z1*Weights[0] + Z2*Weights[1] + Z3*Weights[2]);
      }
  
      public void UpdateWeight(int i, double Wi)
      {
          Weights[i] = Wi;
      }
  }
  </code></pre>
  
  <p>And here is my main class</p>
  
  <pre><code>public class Main
  {
      public int t;
      public Neuron neuron;
      double LearningRate = 0.00001;
      public ArrayList&lt;Marks&gt; TrainingSet, TestSet;
  
      public static void main(String[] args) throws IOException
      {
        Main main = new Main();
          main.run();
      }
  
      public void run()
      {
          TrainingSet = ReadCSV("G:\\EVOS\\EVO_Assignemnt1\\resources\\Streamdata.csv");
          TestSet =  ReadCSV("G:\\EVOS\\EVO_Assignemnt1\\resources\\Test.csv");
          Random ran = new Random();
          neuron = new Neuron(ran.nextDouble(), ran.nextDouble(), ran.nextDouble());
          train();
          Test();
      }
  
  
      public void train()
      {
          t = 0;
          while(t&lt;1000000)
          {
              for(Marks mark: TrainingSet)
              {
                  for(int i=0; i&lt;neuron.Weights.length; i++)
                  {
                      double yp = neuron.FnetLinear(mark.marks[0] , mark.marks[1], mark.marks[2]);
                      double wi = neuron.Weights[i] - LearningRate*(-2*(mark.marks[3]-yp))*mark.marks[i];
                      neuron.UpdateWeight(i, wi);
                  }
              }
              t++;
          }
      }
  
      public void Test()
      {
          System.out.println("Test Set results:");
          int count = 1;
  
          for(Marks mark: TestSet)
          {
              double fnet = neuron.FnetLinear(mark.marks[0] , mark.marks[1], mark.marks[2]);
              System.out.println("Mark " + count + ": " + fnet);
              count++;
          }
      }
  
      public static ArrayList&lt;Marks&gt; ReadCSV(String csv)
      {
          ArrayList&lt;Marks&gt; temp = new ArrayList&lt;&gt;();
          String line;
          BufferedReader br;
          try
          {
           br = new BufferedReader(new FileReader(csv));
              while((line=br.readLine()) != null)
              {
                  String[] n = line.split(",");
                  Marks stud = new Marks(Integer.valueOf(n[0]), Integer.valueOf(n[1]), Integer.valueOf(n[2]), Integer.valueOf(n[3]));
                  temp.add(stud);
              }
          }
          catch (Exception e)
          {
              System.out.println("ERROR");
          }
          return temp;
      }
  }
  </code></pre>
  
  <p>This is the test data with the last number being the actual mark.
  <a href="https://i.stack.imgur.com/idLDx.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/idLDx.png" alt="enter image description here"></a></p>
  
  <p>After running the test data i get results around these:
  <a href="https://i.stack.imgur.com/S8RgA.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/S8RgA.png" alt="enter image description here"></a></p>
  
  <p>As you can see the first 4 marks predictions are way off from the actual mark.
  I followed the text book's explenation of Computational Intlligence An Introduction (Chapter 2 if u are curious).</p>
  
  <p>However I would like to know what I im doing wrong. How can I get more accurate results?</p>