Skip to content
← All PyTorch tracks

Regression from Scratch

PyTorch

Linear, polynomial, regularized, and logistic — the classics every interview revisits.

4 exercises

Explore freely. Sign in to keep your progress.

Your learning sequence

  1. 1 Not solved yet. Linear Regression Practice · Easy
  2. 2 Not solved yet. Polynomial Regression Practice · Medium
  3. 3 Not solved yet. Ridge Regression Practice · Easy
  4. 4 Not solved yet. Logistic Regression From Scratch Practice · Easy

Check yourself

4 questions · not saved while you're signed out

Use these questions to check your understanding and compare explanations. Your score does not affect track completion.

0 / 4 correct

For a squared-error objective, what distinguishes an L1 penalty from a squared L2 penalty when choosing coefficients?

Choose one answer to reveal the explanations. Answers are kept only while this page is open.

import torch

# Minimize 0.5 * (w - a)^2 + strength * penalty(w), component by component.
a = torch.tensor([0.2, 2.0], dtype=torch.float64)
strength = 0.5
l1_solution = a.sign() * (a.abs() - strength).clamp_min(0)
l2_solution = a / (1 + 2 * strength)
print("L1:", l1_solution.tolist())
print("squared L2:", l2_solution.tolist())
Question 1 of 4