We can't find the internet
Attempting to reconnect
Something went wrong!
Attempting to reconnect
← Regression from Scratch step 2 of 4
Medium
End-to-End
Polynomial Regression
Implement polynomial regression by first constructing polynomial features, then applying a linear model.
Given scalar inputs x and a degree d, construct features:
$\phi(x) = [1, x, x^2, ..., x^d]$
Then predict: $\hat{y} = \phi(x) \cdot w$
And compute MSE loss: $L = \frac{1}{N} \sum (y - \hat{y})^2$
Input:
-
x: input tensor of shape(N,) -
w: weight vector of shape(d+1,)for polynomial of degreed -
y: target values of shape(N,)
Output: A dict with “prediction” (shape (N,)) and “loss” (scalar).
Nothing accepted yet. When a submission passes, the code that passed shows up
here, one entry per mode.
Stuck?
PyTorch reference solution
Sign in to attempt this problem and reveal the reference solution.