TensorTonicTensorTonic
Problems
Study PlansProjectsNewInterviewPricingFeedback
Problems
Loading...
1 / 1

Logistic Regression Training Loop

OptimizationLoss Functions
Medium

Train a binary logistic regression classifier using gradient descent. Implement the training loop and return the learned parameters (w, b).

Model:

p=σ(Xw+b)=11+e−(Xw+b)p = \sigma(Xw + b) = \frac{1}{1 + e^{-(Xw + b)}}p=σ(Xw+b)=1+e−(Xw+b)1​

Loss (Binary Cross-Entropy):

L=−1N∑i=1N[yilog⁡pi+(1−yi)log⁡(1−pi)]\mathcal{L} = -\frac{1}{N} \sum_{i=1}^{N} [y_i \log p_i + (1 - y_i) \log(1 - p_i)]L=−N1​i=1∑N​[yi​logpi​+(1−yi​)log(1−pi​)]

Helper Functions Provided

  • _sigmoid(z): numerically stable sigmoid activation
Loading visualization...

Examples

Input: X = [[0], [1], [2], [3]], y = [0, 0, 1, 1], lr = 0.1, steps = 500

Output: ([2.5272], -3.4307)

Hint 1

Compute grad_w with X.T @ (p - y) / len(y) and grad_b with np.mean(p - y).

Hint 2

Update both parameters with the learning rate during every iteration.

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
Try Similar Problems
Cross Entropy LossLog Loss Per SampleSigmoid NumpySoftmax FunctionLinear Regression Closed Form

Sign in to take notes on this problem

Case 1

Accepts: array

Accepts: array

Accepts: number

Accepts: number

You must run your code first.
PrevNext

Logistic Regression Training Loop

OptimizationLoss Functions
Medium

Train a binary logistic regression classifier using gradient descent. Implement the training loop and return the learned parameters (w, b).

Model:

p=σ(Xw+b)=11+e−(Xw+b)p = \sigma(Xw + b) = \frac{1}{1 + e^{-(Xw + b)}}p=σ(Xw+b)=1+e−(Xw+b)1​

Loss (Binary Cross-Entropy):

L=−1N∑i=1N[yilog⁡pi+(1−yi)log⁡(1−pi)]\mathcal{L} = -\frac{1}{N} \sum_{i=1}^{N} [y_i \log p_i + (1 - y_i) \log(1 - p_i)]L=−N1​i=1∑N​[yi​logpi​+(1−yi​)log(1−pi​)]

Helper Functions Provided

  • _sigmoid(z): numerically stable sigmoid activation
Loading visualization...

Examples

Input: X = [[0], [1], [2], [3]], y = [0, 0, 1, 1], lr = 0.1, steps = 500

Output: ([2.5272], -3.4307)

Hint 1

Compute grad_w with X.T @ (p - y) / len(y) and grad_b with np.mean(p - y).

Hint 2

Update both parameters with the learning rate during every iteration.

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
Try Similar Problems
Cross Entropy LossLog Loss Per SampleSigmoid NumpySoftmax FunctionLinear Regression Closed Form

Sign in to take notes on this problem

Case 1

Accepts: array

Accepts: array

Accepts: number

Accepts: number

You must run your code first.