Logistic Regression Training Loop
Logistic Regression Training Loop
Train a binary logistic regression classifier using gradient descent. Implement the training loop and return the learned parameters (w, b).
Model:
p=σ(Xw+b)=1+e−(Xw+b)1Loss (Binary Cross-Entropy):
L=−N1i=1∑N[yilogpi+(1−yi)log(1−pi)]Helper Functions Provided
_sigmoid(z): numerically stable sigmoid activation
Examples
Input: X=[[0],[1],[2],[3]], y=[0,0,1,1], lr=0.1, steps=500
Expected: Accuracy ≥ 95%
Hint 1
Compute gradients:∇w=XT(p−y)/N and ∇b=mean(p−y).
Hint 2
Update parameters:w←w−lr⋅∇w andb←b−lr⋅∇b. Repeat the steps.
Requirements
- Initialize weights w as zeros and bias b as 0.0
- Use gradient descent to minimize the loss function
- Return tuple (w, b) where w is shape (D,) and b is a float
- NumPy only, no sklearn or other ML libraries
Constraints
- Input sizes: N ≤ 200, D ≤ 10
- lr > 0, steps ≥ 1
- Time limit: 1000 ms; Memory ≤ 128 MB
Log in to take notes on this problem
Accepts: array
Accepts: array
Accepts: number
Accepts: number
Logistic Regression Training Loop
Logistic Regression Training Loop
Train a binary logistic regression classifier using gradient descent. Implement the training loop and return the learned parameters (w, b).
Model:
p=σ(Xw+b)=1+e−(Xw+b)1Loss (Binary Cross-Entropy):
L=−N1i=1∑N[yilogpi+(1−yi)log(1−pi)]Helper Functions Provided
_sigmoid(z): numerically stable sigmoid activation
Examples
Input: X=[[0],[1],[2],[3]], y=[0,0,1,1], lr=0.1, steps=500
Expected: Accuracy ≥ 95%
Hint 1
Compute gradients:∇w=XT(p−y)/N and ∇b=mean(p−y).
Hint 2
Update parameters:w←w−lr⋅∇w andb←b−lr⋅∇b. Repeat the steps.
Requirements
- Initialize weights w as zeros and bias b as 0.0
- Use gradient descent to minimize the loss function
- Return tuple (w, b) where w is shape (D,) and b is a float
- NumPy only, no sklearn or other ML libraries
Constraints
- Input sizes: N ≤ 200, D ≤ 10
- lr > 0, steps ≥ 1
- Time limit: 1000 ms; Memory ≤ 128 MB
Log in to take notes on this problem
Accepts: array
Accepts: array
Accepts: number
Accepts: number