Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

#MachineLearning #GradientDescentProgramming #Python Here is the code I have so far: w = np.random.normal(0,1,10) norm = np.linalg.norm(w) norm_w = worm #Generating random data for x,

#MachineLearning #GradientDescentProgramming #Python

image text in transcribed

Here is the code I have so far:

w = np.random.normal(0,1,10) norm = np.linalg.norm(w) norm_w = worm

#Generating random data for x, y def generate_data(m): x_i = [] y_i = [] a = [0, 1] for i in range(1, m): x = np.random.normal(0,1,10) x_i.append(x) b = np.dot(x, norm_w) sigma = 1/(1 + np.exp(-b)) p_y1 = sigma p_y0 = 1 - (sigma) c = random.choices(a, weights = [p_y0, p_y1]) y_i.append(c) i = i + 1 df = pd.DataFrame(x_i) df['y_i'] = y_i return df

df = generate_data(11)

df.head()

def fun(X): return X[0]

#split dataset in features and target variable X = df[[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]] y = df['y_i'].apply(fun)

#Loss_function = (1/2)(((1/(1+exp(-Xw)))-y)^2) #Gradient of the loss function with respect to w grad = (X*np.exp(-(np.dot(X, norm_w)))*((y-1)*np.exp(-(np.dot(X, norm_w)))+y))/((np.exp(-(np.dot(X, norm_w)))+1)**3)

#Update Rule

w_old = norm_w eta = 0.01 w_new = w_old - 1/250*(eta)*(grad) print(w_new)

Need to plot ||w - w_new|| vs m = {50, 100, 150, 200, 250}. Please help? I'd be really grateful if someone can provide the python code/edit my python code above.

Algorithm 2: gradient descent with square loss Define square loss as L(4) = (((( x y) Algorithm 2 is gradient descent with respect to square loss (code this up yourself -- run for 1000 iterations, use step size eta = 0.01). Algorithm 2: gradient descent with square loss Define square loss as L(4) = (((( x y) Algorithm 2 is gradient descent with respect to square loss (code this up yourself -- run for 1000 iterations, use step size eta = 0.01)

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_2

Step: 3

blur-text-image_3

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

Big Data, Mining, And Analytics Components Of Strategic Decision Making

Authors: Stephan Kudyba

1st Edition

1466568704, 9781466568709

More Books

Students also viewed these Databases questions