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. 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. 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. 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 6xl that contains the labels. ii. 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 traininputs, 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 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. input desired predict X1 X2 label the label 2 0 1 2 1 0 0 0 1 -2 0 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. 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. 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. 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 6xl that contains the labels. ii. 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 traininputs, 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 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. input desired predict X1 X2 label the label 2 0 1 2 1 0 0 0 1 -2 0 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