Skip to content

Latest commit

 

History

History

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 

README.md

04 — Logistic Regression

Same loop as linear regression, two changes:

  1. Sigmoid squashes the linear output to (0, 1) — a probability.
  2. Binary cross-entropy loss replaces MSE; it punishes confident wrong answers heavily.

We also introduce two PyTorch building blocks you'll use for every real model:

  • nn.Linear(in, out) — a learnable affine layer. Equivalent to x @ W.T + b.
  • torch.optim.SGD — wraps the "subtract learning rate times gradient" step.

Why BCEWithLogitsLoss instead of Sigmoid + BCE?

It's the same math, but combining them avoids a numerical-stability problem (the log of a near-zero sigmoid output blows up). Use the combined loss in real code.

Run

python 04_logistic_regression/main.py