Question: 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

1 Expert Approved Answer
Step: 1 Unlock

python import numpy as np def logisticregressionX y maxiter alpha Trains the logistic regression cla... View full answer

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 Programming Questions!