Cost Function and Equation Derivation

Since we already have the linear regression equation

and a corresponding loss function

We can now just solve for w. This can actually be done with a closed form solution, specifically, we can use Lagrange multipliers to solve for w directly.

We can rewrite J(w) as:

Where A is the matrix whose rows are each x vector, w is the weight vector, y a column of labels corresponding to each x in A, and the entire term Aw - y, is a column vector of differences between model predictions and true labels. An element wise sum of a vector v can be written V*V, hence the final form. This term is scalar valued, just like the original expression of J.

In this form, the function can be easily differentiated with respect to w, and solved closed form as follows:

We set the derivative to zero,

This form can can also be expressed as the pseudo-inverse of A multiplied by y

This means that for any dataset, we simply take the pseudoinverse of the features (concatenated by a vector of ones first!) and multiply it against the labels, and this gives us the ideal fitting parameters for our training data!

results matching ""

    No results matching ""