XGBRegressor - using sklearn.metrics function as objective

Hi. I’ve implemented an XGB model with the Scikit-Learn interface and would like to use MAPE as objective/loss. I’ve encountered 3 different parameters that can be sent to the XGBRegressor object: objective, obj, and eval_metric. eval_metric would be perfect for my case, as I can then use the sklearn.metrics.mean_absolute_percentage_error function. According to the XGB documentation this should be possible. I noticed however that it says “XGBoost 1.6.0 users”, when the latest version is 1.5.2. Is this an unreleased feature or is this an error in the documentation?

On another note, I can’t really tell if it is working as intended or if it’s just using the default objective='reg:squarederror'. Anyone that can help me with this? Thanks ahead of time.

XGBoost actually offers MAPE as a built-in metric. Pass eval_metric='mape' when calling the fit() method.

As for the objective, you cannot optimize MAPE directly; instead, you use objective='reg:squarederror' which optimizes the L2 loss. You can use early stopping with the MAPE metric on a validation data set in order to choose the best model.