Question: Problem) Gradient descent learning in Python: 1. a) Create class NeuralNetwork(): that creates a single neuron with a linear activation, train it using gradient
Problem) Gradient descent learning in Python: 1. a) Create class NeuralNetwork(): that creates a single neuron with a linear activation, train it using gradient descent learning. This class should have the following function: def __init__(self, learning_r): that initializes a 3x1 weight vector randomly and initializes the learning rate to learning_r. Also, it creates a history variable that saves the weights and the training cost after each epoch (i.e., iteration). def sigmoid(self, x): that takes an input x, and applies the sigmoid function to return: ii. iii. iv. b) Use the gradient descent rule to train a single neuron on the datapoints given below: Create an np array of a shape 10x2 that contains the inputs, and another array with a shape 10x1 that contains the labels. i. ii. iii. p(x) = 1 1+ex def forward_propagation(self, inputs): that performs forward propagation by multiplying the inputs by the neuron weights, uses sigmoid activation function and then generates the output. def train(self, inputs_train, labels_train, num_train_iterations): that performs the gradient descent learning rule for num_train_iterations times using the inputs and labels. iv. Plot the given data points with two different markers for each group. Add the bias to the inputs array to have a 10x3 shape. Create the network with one neuron using the class NeuralNetwork() with learning rate of 1 then train it using train(inputs, labels, 50) function. input X1 X2 1 1 1 0 0 1 0.5 -1 1 0.5 3 0.7 2 -1 0 -1 1 2 0 0 0 desired label 1 1 0 0 1 1 0 0 1 0 c) Use the trained weights and plot the final classifier line. d) Plot the training cost (i.e., the learning curve) for all the epochs. e) Repeat step (b.iv) with the learning rates of 0.5, 0.1, and 0.01. Plot the final classifier line and the learning curve for each learning rate. f) What behavior do you observe from the learning curves with the different learning rates? Explain your observations. Which learning rate is more suitable? Explain.
Step by Step Solution
3.38 Rating (160 Votes )
There are 3 Steps involved in it
a Heres an implementation of the NeuralNetwork class with the required functions python import numpy as np import matplotlibpyplot as plt class NeuralNetwork def initself learningr selfweights nprando... View full answer
Get step-by-step solutions from verified subject matter experts
