easy end_to_end

Binary Classifier

Build a binary classifier that outputs a probability using sigmoid.

The forward pass computes:

  1. Linear: $z = x \cdot W + b$
  2. Sigmoid: $p = \sigma(z) = \frac{1}{1 + e^{-z}}$

Also compute the Binary Cross-Entropy (BCE) loss: $$\text{BCE} = -\frac{1}{N}\sum [y \log(p) + (1-y)\log(1-p)]$$

Input:

  • x: input tensor of shape (batch, features)
  • W: weight matrix of shape (features, 1)
  • b: bias scalar of shape (1,)
  • y: target labels of shape (batch, 1) with values 0 or 1

Output: A dict with “prediction” (shape (batch, 1)) and “loss” (scalar).

Hints

binary-classification sigmoid bce-loss logistic-regression
Detecting runtime...