Problem 2.1
To walk “downhill” on the least squares loss function
we measure its its gradient with respect to the parameters and . Calculate expressions for the slopes and .
For :
Taking the summation into account, we have
For :
Taking the summation into account, we have:
Problem 2.2
Show that we can find the minimum of the loss function in closed form by setting the expression for the derivatives from Problem 2.1 to zero and solving for and . Note that this works for linear regression but not for more complex models; this is why we use iterative model fitting methods like gradient descent.
For :
For :
Substitute into the equation:
Then:
Problem 2.3
Consider reformulating linear regression as a generative model, so we have . What is the new loss function? Find an expression for the inverse function that we would use to perform inference. Will this model make the same predictions as the discriminative version for a given training dataset ? One way to establish this is to write code that fits a line to three data points using both methods and see if the result is the same.
The generative model is
Here, is generated as a function of and parameters .
The new least squares loss becomes:
We want to find the inverse function , starting from:
- The discriminative model directly minimizes the loss on given .
- The generative model minimizes the loss on given , and we invert it to predict from .
Discriminative Model: y = 1.17 + 0.75x
Generative Model: x = -1.43 + 1.29y
Inverse Generative Model: y = 1.11 + 0.78x