https://github.com/marimo-team/modernaicourse/blob/main/concepts/02_supervised_learning.py
This notebook demonstrates supervised learning with a simple binary
classifier trained on real cat and dog photos. We download a public dataset,
resize the images, extract pixel features, and train a logistic regression
model with PyTorch to tell cats from dogs.
Dataset ready at dog-cat-full-dataset/data
Loaded 10000 training images and 1000 test images (resized to 64x64 RGB).
The model minimizes the binary cross-entropy loss over the training set:
| Symbol | Meaning | In this task |
|---|---|---|
| Number of training samples | 10,000 images (5,000 cats + 5,000 dogs) | |
| Ground-truth label for sample | 0 = Cat, 1 = Dog | |
| Feature vector for sample | 12,288-dim vector (64 × 64 × 3 RGB pixels) | |
| Predicted probability that sample is a dog | Model's confidence the photo is a dog |
When the true label is dog (), only the term is active, penalizing low confidence. When the true label is cat (), only the term is active, penalizing high confidence. SGD adjusts and to minimize .
| Metric | Value |
|---|---|
| Training samples | 10000 |
| Test samples | 1000 |
| Features per image | 12288 |
| Epochs | 100 |
| Train accuracy | 67.6% |
| Test accuracy | 61.1% |
nn.Linear layer
(12,288 -> 2) trained with SGD and cross-entropy loss in PyTorch.torch.softmax converts the raw logits into a probability distribution
over the two classes.