Negative MAE value in XGBRegressor

45 Views Asked by At

Background: I have a tabular dataset and I am trying to predict price values. Two type of features are available where some columns are categorical variables(as dummy) and other features where the values vary between 0 and 1.

from xgboost import XGBRegressor
from sklearn.model_selection import GridSearchCV
from sklearn.metrics import make_scorer

def mean_absolute_error(y_true, y_pred):
    return np.mean(np.abs((y_true - y_pred) / y_true))
scoring_function = make_scorer(mean_absolute_error, greater_is_better=False)
xgb_estimator = XGBRegressor(nthread=4,seed=42,tree_method='gpu_hist')

xgb_parameters = {
    'max_depth': [5,10,15,None],
    'n_estimators': [50,100,150,200],
    'learning_rate': [0.1,0.01,0.001],
    
}
xgb_grid_search = GridSearchCV(
    estimator=xgb_estimator,
    param_grid=xgb_parameters, scoring=scoring_function,
    n_jobs = -1,cv = 5,verbose=True)

xgb_grid_search.fit(X_train, y_train)
>>> xgb_grid_search.best_estimator_.score(X_train,y_train)
-0.6489206764616637

Why am I getting a negative result for the mae value, which should be positive by definition?

0

There are 0 best solutions below