title: Python Perceptron not working, doesn't seem to train using no library only numpy
body: <p>I can't figure out why my perceptron isn't working, it's not learning off the training data and I'm not sure why. it's getting errors each epoch and converge, am I missing something here?
  Here's the source code.</p>
  <pre><code>import numpy as np
  import matplotlib.pyplot as plt
   
  trainData = np.genfromtxt('train.data', delimiter=&quot;,&quot;)
  testData = np.genfromtxt('test.data', delimiter=&quot;,&quot;)
   
   
  class Perceptron():
   
      def __init__(self, learnRate, maxEpoch):
          self.learnRate = learnRate
          self.maxEpoch = maxEpoch
   
      def train(self, data):
   
          np.random.seed(2)
          x0 = np.ones((len(data),1))
          w0 = np.zeros((1))
          weights = np.random.rand((len(data[0]))-1)
          weights = np.hstack([w0,weights])
          data = np.hstack([x0,data])
          np.random.shuffle(data)
          label = data[:,5:]
          data = data[:,:5]
          iter = 0
          for epoch in range(self.maxEpoch): #trainign
              errors = 0
              rowCount = 0
              for row in data:
                  activation = np.inner(row, weights)
                  y = label[rowCount]# Class label
                  rowCount += 1
                  if y * activation &lt;= 0:
                      for wx in weights:
                          wx = wx + y * row[int(wx)]
                          weights[0] = weights[0] + y
                      errors += 1
              iter += 1
          print(f'Errors total: {errors}')
          return weights
   
   
  def classPicker(classX, classY):
      set1 = trainData[:40,:4]
      set2 = trainData[40:80,:4]
      set3 = trainData[80:120,:4]
      class0 = np.full((40,1),-1)
      class1 = np.ones((40,1))
   
      if classX == 1 and classY == 2:
          return np.vstack([np.hstack([set1,class0]),np.hstack([set2,class1])])
      if classX == 2 and classY == 3:
          return np.vstack([np.hstack([set2,class0]),np.hstack([set3,class1])])
      if classX == 1 and classY == 3:
          return np.vstack([np.hstack([set1,class0]),np.hstack([set3,class1])])
   
   
  #Class 1 &amp; 2
  pececptron1 = Perceptron(1,20)
  trainDataset = (classPicker(1,2))
  pececptron1.train(trainDataset)
   
  #Class 2 &amp; 3
  #pececptron2 = Perceptron(1,1)
  #trainDataset = classPicker(2,3)
  #pececptron2.train(trainDataset)
   
  #Class 1 &amp; 3
  #pececptron3 = Perceptron(1,1)
  #trainDataset = classPicker(1,3)
  #pececptron3.train(trainDataset)
  </code></pre>
  <p>the dataset is a modified version of the iris dataset.
  the data arrays looks like this at line 25, just before the training loops.</p>
  <pre><code>label = 40 x 1 array of 1 or -1 depending on class
  weights = [0, 0.4359949, 0.02592623, 0.54966248, 0.43532239] first entry in all weights = w0 aka bias
  data =  [1, 5, 3.4, 1.5, 0.2] first entry in all  = x0 (1) for the bias
  </code></pre>