DL Unit-2 Notes PPT
DL Unit-2 Notes PPT
class Perceptron:
def __init__(self, num_features, learning_rate=0.1,
max_epochs=100):
self.weights = np.zeros(num_features)
self.bias = 0.0
self.learning_rate = learning_rate
self.max_epochs = max_epochs
simple implementation of the perceptron algorithm for
email spam classification using Python:
def train(self, X, y):
for epoch in range(self.max_epochs):
misclassified = 0
for i in range(len(X)):
prediction = self.predict(X[i])
error = y[i] - prediction
if error != 0:
misclassified += 1
self.weights += self.learning_rate * error * X[i]
self.bias += self.learning_rate * error
if misclassified == 0:
break
simple implementation of the perceptron algorithm for
email spam classification using Python:
def predict(self, x):
activation = np.dot(self.weights, x) + self.bias
return np.sign(activation)
plt.show()
simple implementation of the perceptron algorithm for
email spam classification using Python:
# Example usage:
X = np.array([[1, 1], [2, 3], [4, 5], [5, 4]]) # Feature vectors of
emails
y = np.array([0, 0, 1, 1]) # Class labels (0 for not spam, 1 for
spam)
perceptron = Perceptron(num_features=X.shape[1])
perceptron.train(X, y)