Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Spatio Temporal Database Management International Workshop Stdbm 99 Edinburgh Scotland September 10 11 1999 Proceedings Lncs 1678

Authors: Michael H. Bohlen ,Christian S. Jensen ,Michel O. Scholl

1999th Edition

3540664017, 978-3540664017

More Books

Students also viewed these Databases questions

Question

Compute for each of the regressions.

Answered: 1 week ago

Question

2. How will the team select a leader?

Answered: 1 week ago