Practical Exercises Chapter 1
Exercise 1: Implementing a Simple Perceptron
Task: Implement a perceptron for the AND logic gate. Train the perceptron using the Perceptron learning algorithm and test it on the same data.
Solution:
def __init__(self, learning_rate=0.01, n_iters=1000):
self.learning_rate = learning_rate
n_samples, n_features = X.shape
self.weights = np.zeros(n_features)
for _ in range(self.n_iters):
for idx, x_i in enumerate(X):
linear_output = np.dot(x_i, self.weights) + self.bias
y_predicted = self.activation_function(linear_output)
update = self.learning_rate ...