Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Problem 4) Perceptron learning in Python: a) Create class NeuralNetwork(): that creates a single neuron, train it, and test it. This class should have the
Problem 4) Perceptron learning in Python: a) Create class NeuralNetwork(): that creates a single neuron, train it, and test it. This class should have the following function: i. def init (self): that initializes a 3xl weight vector randomly and initializes the learning rate to 1. ii. def hard_limiter(self, x): that performs the hard-limiter activation on the nx1 vector x. def forward propagation(self, inputs): that performs the forward propagation by multiplying the inputs by the neuron weights and then passing the output through the hard_limiter activation function. iv. def train(self, inputs, labels, num train iterations=10): that performs the perceptron learning rule for num_train_iterations times using the inputs and labels. V. def pred(self, inputs): that classifies the inputs to either class 0 or 1 by multiplying them by the neuron weights, passing the output through the hard limiter activation function and thresholding. b) Use the perceptron learning rule to train a single neuron perceptron on the data points given in problem 3 as follow: i. Create an np array of shape 6x2 that contains the inputs, and another array with shape 6x1 that contains the labels. Add the bias to the inputs array to have 6x3 shape. iii. Create the network with one perceptron using the class NeuralNetwork() then train it using train(inputs, labels, 100) function. c) Plot the given data points with two different markers for each group. d) Using the trained perceptron weight, plot the classifier line in the same plot in (c). e) Using the trained perceptron, classify the test data points given in the table below by calling pred() function. 115 predict the label input X1 X2 2 0 2 1 0 0 -2 0 desired label 1 0 1 0 Problem 4) Perceptron learning in Python: a) Create class NeuralNetwork(): that creates a single neuron, train it, and test it. This class should have the following function: i. def init (self): that initializes a 3xl weight vector randomly and initializes the learning rate to 1. ii. def hard_limiter(self, x): that performs the hard-limiter activation on the nx1 vector x. def forward propagation(self, inputs): that performs the forward propagation by multiplying the inputs by the neuron weights and then passing the output through the hard_limiter activation function. iv. def train(self, inputs, labels, num train iterations=10): that performs the perceptron learning rule for num_train_iterations times using the inputs and labels. V. def pred(self, inputs): that classifies the inputs to either class 0 or 1 by multiplying them by the neuron weights, passing the output through the hard limiter activation function and thresholding. b) Use the perceptron learning rule to train a single neuron perceptron on the data points given in problem 3 as follow: i. Create an np array of shape 6x2 that contains the inputs, and another array with shape 6x1 that contains the labels. Add the bias to the inputs array to have 6x3 shape. iii. Create the network with one perceptron using the class NeuralNetwork() then train it using train(inputs, labels, 100) function. c) Plot the given data points with two different markers for each group. d) Using the trained perceptron weight, plot the classifier line in the same plot in (c). e) Using the trained perceptron, classify the test data points given in the table below by calling pred() function. 115 predict the label input X1 X2 2 0 2 1 0 0 -2 0 desired label 1 0 1 0
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started