Question: Deep Leaning Assignment - Implementing Logistic Regression Implementing Logistic Regression In this assignment, we will implement logistic regression. In the module, we defined data as

Deep Leaning Assignment - Implementing Logistic Regression

Deep Leaning Assignment - Implementing Logistic Regression Implementing Logistic Regression In this

Implementing Logistic Regression In this assignment, we will implement logistic regression. In the module, we defined data as follows. N data points: x; for i = 1,2,....N Each data has dimensions: x = xil X2 Each data has a corresponding class label: y = 0 or 1 XipE RIXD Let's say N = 2000, D = 2 for i = 1, ..., 1000, we use np.random.randn(N, 2) + np.array( [0.9, 0.9]) as X, and y; = 0 for i = 1001, ..., 2000, we use np.random.randn(N, 2) + np.array([-0.9, -0.9]) as X, and y; = 1. Yes, it's two 2D Gaussians centered in different points. Task: Implement logistic regression using the setting above. The following class is prepared for you to help implementation. (But you don't have to use it if you do not like it.) In [3]; import numpy as np class Two2dGaussianData (object): Dataset of two 2d gaussian as a toy binary classification def_init__(self): initialize data with 2000 data points for training, 200 data points for validiation, 200 data points for test N = 1200 x0 = np.random.randn(N, 2) + np.array( [0.9, 0.91) xl = np.random.randn(N, 2) + np.array([-0.9, -0.9]) self.x = { self.x["train"]=np.vstack((x0[0:1000], x1[0:1000])) self.x["val"]=np.vstack((x0[1000:1100], x1[1000:1100])) self.X["test"]=np.vstack((x0[1100:1200), x1[1100:1200])) yO=np.zeros(N)#.astype (np.int) yl=np.ones (N)#.astype (np.int) self.y={} self.y["train"]=np.hstack((y0 [0:1000), yl[0:1000])) self.y["val"]=np.hstack((y0[1000:1100), yi[1000:1100])) self.y["test"]=np. hstack((y0[1100:1200], y1[1100:1200])) def get_batch(self, batch_size, mode="train"): #get random batch num_all_data=len(self.X[mode]) random_indices=np.random.choice(num_all_data, batch_size, replace=False) Xbatch=self.X[mode ] [random_indices ] ybatch=self.y[mode ] [random_indices ] return Xbatch, ybatch

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!