コード例 #1
0
         b = np.concatenate((v2,-1*l),axis = 1)
# concatenate the data to form a single training set
         train_data = np.concatenate((a,b),axis =0)
         return train_data
# Instantiate the class Perceptron
c,d = data_generate(60) # Generate test data
show_data(c,d)
# Add labels +1 to 'a' and -1 to 'b'
Training = labels(60,c,d)
w = Perceptron() # Instantiate the Perceptron class
# Now pass the training data for the perceptron to learn the weight vectors 
# using the Rosenblatt learning algorithm
weight_vector = w.learning(Training)

t1,t2 = data_generate(10)
Test = labels(10,t1,t2)
correct = 0
incorrect = 0
for x in Test:
    d =	x[3]
    x = np.delete(x,3)
    y = w.response(np.vdot(weight_vector,x))
    if y == d:
       correct+=1
    else:
       incorrect+=1

print 'Number of correctly classified points is' +' '+str(correct)
print 'Number of incorrectly classified points is' +' '+str(incorrect)