Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

D ef logistic _ _ regression ( ( X , , y , , max _ _ iter, alpha ) ) : '

 Def logistic_regression(X, y, max_iter, alpha): 
 
'''" id="MathJax-Element-7-Frame" role="presentation" style="font-size: 121%; position: relative;" tabindex="0">'''
Trains the logistic regression classifier on data X and labels y using gradient descent for max_iter iterations with learning rate alpha.
Returns the weight vector, bias term, and losses at each iteration AFTER updating the weight vector and bias.
Input:
X: data matrix of shape nxd
y: n-dimensional vector of data labels (+1 or -1)
max_iter: number of iterations of gradient descent to perform
alpha: learning rate for each gradient descent step
Output:
w, b, losses
w: d-dimensional weight vector
b: scalar bias term
losses: max_iter-dimensional vector containing negative log likelihood values AFTER a gradient descent in each iteration
'''" id="MathJax-Element-18-Frame" role="presentation" style="font-size: 121%; position: relative;" tabindex="0">'''
n, d = X.shape
w = np.zeros(d)
b =0.0
losses = np.zeros(max_iter)
for step in range(max_iter):
# YOUR CODE HERE.

Step by Step Solution

3.44 Rating (151 Votes )

There are 3 Steps involved in it

Step: 1

python import numpy as np def logisticregressionX y maxiter alpha Trains the logistic regression cla... 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

Corporate Finance

Authors: Stephen Ross, Randolph Westerfield, Jeffrey Jaffe

13th International Edition

1265533199, 978-1265533199

More Books

Students also viewed these Programming questions