90.4k views
1 vote
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: i. def_init__(self, learning_r): that initializes a 3xl 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 forward propagation(self, inputs): that performs the forward propagation by multiplying the inputs by the neuron weights and then generating the output. iii. def train(self, inputs_train, labels_train, num_train_epochs=10): that performs the gradient descent learning rule for num_train_epochs times using the inputs and labels. This function also saves the weights and costs at every epoch to the history variable. b) Use the gradient descent rule to train a single neuron on the datapoints, given below, as follow: i. Create an np array of shape 10x2 that contains the inputs, and another array with shape 10x1 that contains the labels. ii. Add the bias to the inputs array to have 10x3 shape. iii. Create the network with one neuron using the class NeuralNetwork() with learning rate of 1 then train it using train(inputs, labels, 50) function. desired label 1 1 input X1 X2 1 1 1 0 0 1 -1 -1 0.5 3 0.7 2 -1 0 -1 1 2 0 -2 -1 -1 c) Plot the given data points with two different markers for each group. d) Use the trained weights at each epoch and plot the classifier lines of every 5 epochs (i.e., 1,5,10, ..., 50) to the plot in (C). e) Use the trained weights and plot the final classifier line to the plot in (c). f) Plot the training cost (i.e., the learning curve) for all the epochs. g) Repeat step (b) with the learning rates of 0.5 and 0.05. Create a subplot with the learning curves of learning rates 1, 0.5, and 0.05. Add titles. h) What behavior do you observe from the learning curves with the different learning rates? Explain your observations. Which learning rate is more suitable? Explain.

User Pooja Shah
by
7.8k points

1 Answer

5 votes

Answer:

4

Explanation:

User DMIL
by
8.7k points