What quantities must a custom objective function supply to XGBoost or LightGBM?

Quick Overview

Asks what a custom objective function has to return to XGBoost or LightGBM and why the library needs it. Tests how gradient boosting builds leaves and scores splits, the function signatures, and the practical pitfalls of writing your own loss.

What quantities must a custom objective function supply to XGBoost or LightGBM?

Role: Machine Learning Engineer

Category: Machine Learning

Difficulty: medium

Interview Round: Other

You want to train XGBoost or LightGBM with a loss that is not built in. What quantities must a custom objective function supply to XGBoost or LightGBM, and why does the library need them? ```hint Think about the update Recall how these libraries compute the value of a new leaf. What kind of optimization step is it, and which derivatives does that step need? ``` ```hint Check the input scale Ask whether the predictions your function receives are probabilities or something else. ``` ### What a Strong Answer Covers - The quantities returned, their shape, and the variable they are computed with respect to - Why the library needs each one, for leaf weights and for split gain - The function signatures in the native and scikit-learn APIs - Practical pitfalls about the input scale, numerical stability, the initial score, the evaluation metric and the prediction output ### Follow-up Questions - How would you write the objective for a log loss that weights missed positives more heavily? - How would you handle mean absolute error as a custom objective? - How does the library use these quantities to choose between candidate splits? - How would you check a custom objective's output before training on real data?

Overview: Asks what a custom objective function has to return to XGBoost or LightGBM and why the library needs it. Tests how gradient boosting builds leaves and scores splits, the function signatures, and the practical pitfalls of writing your own loss.

PracHub logo
General
Nov 24, 2026
mediumMachine Learning EngineerOtherMachine Learning
0
0

You want to train XGBoost or LightGBM with a loss that is not built in. What quantities must a custom objective function supply to XGBoost or LightGBM, and why does the library need them?

What a Strong Answer Covers Guidance

  • The quantities returned, their shape, and the variable they are computed with respect to
  • Why the library needs each one, for leaf weights and for split gain
  • The function signatures in the native and scikit-learn APIs
  • Practical pitfalls about the input scale, numerical stability, the initial score, the evaluation metric and the prediction output

Follow-up Questions Guidance

  • How would you write the objective for a log loss that weights missed positives more heavily?
  • How would you handle mean absolute error as a custom objective?
  • How does the library use these quantities to choose between candidate splits?
  • How would you check a custom objective's output before training on real data?