We can't find the internet
Attempting to reconnect
Something went wrong!
Attempting to reconnect
Regression from Scratch
PyTorchLinear, polynomial, regularized, and logistic — the classics every interview revisits.
4 exercises
Explore freely. Sign in to keep your progress.
Your learning sequence
- 1 Not solved yet. Linear Regression Practice · Easy
- 2 Not solved yet. Polynomial Regression Practice · Medium
- 3 Not solved yet. Ridge Regression Practice · Easy
- 4 Not solved yet. Logistic Regression From Scratch Practice · Easy
Check yourself
4 questions · not saved while you're signed outUse these questions to check your understanding and compare explanations. Your score does not affect track completion.
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())