Is sklearn.metrics.mean_squared_error the larger the better (negated)?

The actual function "mean_squared_error" doesn't have anything about the negative part. But the function implemented when you try 'neg_mean_squared_error' will return a negated version of the score.

Please check the source code as to how its defined in the source code:

neg_mean_squared_error_scorer = make_scorer(mean_squared_error,
                                        greater_is_better=False)

Observe how the param greater_is_better is set to False.

Now all these scores/losses are used in various other things like cross_val_score, cross_val_predict, GridSearchCV etc. For example, in cases of 'accuracy_score' or 'f1_score', the higher score is better, but in case of losses (errors), lower score is better. To handle them both in same way, it returns the negative.

So this utility is made for handling the scores and losses in same way without changing the source code for the specific loss or score.

So, you did not miss anything. You just need to take care of the scenario where you want to use the loss function. If you only want to calculate the mean_squared_error you can use mean_squared_error only. But if you want to use it to tune your models, or cross_validate using the utilities present in Scikit, use 'neg_mean_squared_error'.

Maybe add some details about that and I will explain more.


It's a convention for implementing your own scoring object [1]. And it must be positive, because you can create a non-loss function to compute a custom positive score. That means that by using a loss function (for a score object) you have to the negative value.

The range of a loss function is: (optimum) [0. ... +] (e.g. unequal values between y and y'). For instance check the formula of the mean squared error, it's always positive:

mean squared error

Image source: http://scikit-learn.org/stable/modules/model_evaluation.html#mean-squared-error