Exemple #1
0
import numpy as np
from utils import load_iris
from Answer import Perceptron
"""
Main code to run Perceptron Learning Algorithm
"""

x_train, y_train, x_test, y_test = load_iris('./data')

num_features = x_train.shape[1]
perceptron = Perceptron(num_features)

# =============== EDIT HERE ===============
# Try one of two train algorithm at a time (stochastic or batch)
# Test acc. should be 1.0 at both case

learning_rate = 0.001

perceptron.stochastic_train(x_train, y_train, learning_rate)
# perceptron.batch_train(x_train, y_train, learning_rate)

# =========================================

pred = perceptron.forward(x_test)
correct = len(np.where(pred.reshape(-1) == y_test)[0])
total = len(y_test)

print('Test Accuracy : %.2f' % (correct / total))
Exemple #2
0
import numpy as np
from utils import load_iris
from Answer import Perceptron

"""
Main code to run Perceptron Learning Algorithm
"""

x_train, y_train, x_test, y_test = load_iris('./data')

num_features = x_train.shape[1]
perceptron = Perceptron(num_features)

# =============== EDIT HERE ===============
# Try one of two train algorithm at a time (stochastic or batch)
# Test acc. should be 1.0 at both case

learning_rate = 0.1

#perceptron.stochastic_train(x_train, y_train, learning_rate)
perceptron.batch_train(x_train, y_train, learning_rate)

# =========================================

pred = perceptron.forward(x_test)
correct = len(np.where(pred.reshape(-1) == y_test)[0])
total = len(y_test)

print('Test Accuracy : %.2f' % (correct / total))
Exemple #3
0
- Your codes are supposed to make same results as mine.
- Please do not code any other functionality other than what is said to do. 
  You will not get the same results, otherwise.
  ex) shuffle data every epoch (You don't need to care this. But you can try personally.)
  
"""
"""
sign(temp1) should be exactly same as below:
sign(temp1) 의 결과는 아래와 일치해야 합니다:
[[ 1. -1.  1.]
 [-1.  1.  1.]]
"""
temp1 = np.array([[0.1, -2, 123], [-123, 11, 0.0]])
print(sign(temp1))

perceptron = Perceptron(3)
temp_w = np.array([[1.0, -2.0, 3.0]]).T
temp_b = np.array([1.0])
perceptron.W = temp_w
perceptron.b = temp_b
"""
forward(temp2), forward(temp3) should be exactly same as below:
forward(temp2), forward(temp3) 의 결과는 아래와 일치해야 합니다:
[[1.]]
[[-1.]]
"""

temp2 = np.array([[10, -10, 1]])
print(perceptron.forward(temp2))

temp3 = np.array([[-0.1, 0.9, -1.0]])