XGBRegressor 中的负 MAE 值

问题描述 投票:0回答:0

背景:我有一个表格数据集,我正在尝试预测价格值。有两种类型的特征可用,其中一些列是分类变量(作为虚拟变量),而其他特征的值在 0 和 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

为什么我得到的 mae 值是负值,而根据定义,mae 值应该是正值?

machine-learning regression xgboost xgbregressor
© www.soinside.com 2019 - 2024. All rights reserved.