why did we use ' - ' (negative) sign before cross_val_score

Viewed 70

why did we use ' -cross_val_score ' instead of just cross_val_score?

cv_mae = -cross_val_score(lm,
                         x_train,y_train,
                         cv=10,
                         scoring='neg_mean_absolute_error')
1 Answers

This is due to a convention in scikit-learn:

All scorer objects follow the convention that higher return values are better than lower return values. Thus metrics which measure the distance between the model and the data, like metrics.mean_squared_error, are available as neg_mean_squared_error which return the negated value of the metric.

(quoted from here)

Since your cross_val_score returns the negative MAE (see that you passed scoring='neg_mean_absolute_error' as a parameter), you need the negative sign to get the actual MAE.

Related