Question: Logistic Regression with Stochastic Gradient Descent In this question, you are asked to implement stochastic gradient descent (perceptron learning in slides) to learn the weights

Logistic Regression with Stochastic Gradient Descent In this question, you are asked to implement stochastic gradient descent (perceptron learning in slides) to learn the weights for logistic regression. The input variables (X) are the positions of 400 different points, the response variable (y) is the class that each x in X should belong to. Note that you only have two classes 0 and 1. Here are the instructions: Use the code provided to generate data set X and y, Visualize the data in scatter plot with various colors for different classes. Insert a column of ones as the bias in the input variable matrix X the activation function we use in this question is sigmoid. Write a function to calculate the output of sigmoid activation function for a given input t S(t) =1/1 + e^-t

Randomly Initialize the weight matrix and set up a learning rate. Pick first row form the matrix X, use the current weight matrix and sigmoid function to calculate the current output. Calculate the error and update the weight matrix. (Note: The error is de ned as the squares error) Repeat several passes over the entire training data set until converge. Average the loss for each epoch and Visualizes it. (Note: One epoch means a single pass through the entire training set ) Use final weight matrix to plot the line to separate points on the same plot in first step.

The code to be used for generating the dataset X,y is given below:

from sklearn.datasets.samples_generator import make_blobs (X, y) = make_blobs(n_samples=400, n_features=2, centers=2, cluster_std=2.5, random_state=95) print (X, y)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!