Skip to main content

Lab 2: Logistic regression

From training-data EDA to nonlinear decision boundaries

Overview

In this 90-minute lab, you will investigate how data representation changes logistic-regression training and decision boundaries on the Breast Cancer Wisconsin Diagnostic dataset. Malignant is treated as the positive class.

You will compare four PyTorch pipelines: all raw features, all standardized features, two standardized PCA components, and standardized quadratic features constructed from those same components. The comparison separates scaling and optimization, dimensionality reduction, and nonlinear representation.

Learning objectives

By the end of the lab, you should be able to:

  • connect training-data EDA to testable modelling hypotheses;
  • fit preprocessing only on training data and keep validation and test roles distinct;
  • derive logistic-regression BCE gradients with tensors and verify them using autograd;
  • implement a custom PyTorch Dataset, DataLoader, model, loss, optimizer, and training loop;
  • interpret learning curves, classification metrics, PCA explained variance, and decision boundaries;
  • select a pipeline with validation evidence and evaluate it once on test data.

Start the lab

Open in Google Colab

Download the student notebook

If direct Colab access is unavailable, download the notebook, open Google Colab, choose File → Upload notebook, and save your own copy before editing.

Submission checklist

  • Complete all eight TODO(student) tasks.
  • Restart the runtime and run every cell in order.
  • Confirm that all gradient, tensor-shape, preprocessing, model-output, and training-behavior assertions pass.
  • Include the A–D comparison table, learning curves, and C/D boundary plot.
  • Answer all seven interpretation questions in your own words.
  • Be prepared to explain or modify any submitted code during the lab defence.

Chats may be used as tutors for explanations, incremental hints, and debugging. Students remain responsible for every submitted line and may not use a chat to complete assessed tasks or write questionnaire answers.

The lab was developed by Alexei Kornaev, with AI-assisted drafting and review using ChatGPT (OpenAI). The instructor retains responsibility for the learning design, technical accuracy, and assessment.