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')
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')
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 asneg_mean_squared_errorwhich 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.