Sobes.tech
Middle — Senior

What is the gradient formula for MSE with respect to weights?

sobes.tech AI

Answer from AI

The Mean Squared Error (MSE) loss function for a single example:

[ L = \frac{1}{2}(y - \hat{y})^2 ]

where ( y ) is the true value, ( \hat{y} ) is the model's prediction.

If ( \hat{y} = \sum_i w_i x_i ), then the gradient with respect to the weight ( w_j ) is calculated as:

[ \frac{\partial L}{\partial w_j} = (\hat{y} - y) \cdot x_j ]

That is, the error (the difference between the prediction and the true value) is multiplied by the corresponding input variable.

This expression is used in gradient descent to update the weights:

w_j := w_j - \eta \cdot \frac{\partial L}{\partial w_j}

where ( \eta ) is the learning rate.