Skip to content
Advertisement

xlearn predictions error give a different mse than output by the function

the xlearn predict function gives a different mse than what you get by looking at the predictions and calculating it yourself. Here is code to do this; you can run it by cloning the xlearn repository and copying the below code in demo/regression/house_price in the repository

JavaScript

If you save it as min_eg.py, run it (after installing xlearn) as python min_eg.py simply.

Here is the output you get:

output snapshot

Interestingly the MSE you get is always exactly double of the reported mse from the predict function.

Any help is greatly appreciated; and I wonder if other folks have encountered the same issue.

Advertisement

Answer

A lot of people use 1/2 MSE for the loss because it makes the derivative “easier”. Given that they use the word “loss” rather than “MSE” or something like that, I’d bet this is what’s going on.

For clarity, if your loss is

1/2n * [(y_1 – p_1)^2 + … + (y_n – p_n)^2]

then the derivative (wrt p) would be

-1/n * [(y_1 – p_1) + … + (y_n – p_n)]

The 2 goes away because you end up multiplying by 2 for the power rule.

pardon the formatting… I don’t know how to do math stuff here.

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement