Skip to content

[RFC] provide Python/R implementations of all the built-in objectives? #6440

Open
@jameslamb

Description

Summary

Should we provide example Python (and maybe R) implementations of LightGBM's objective functions which exactly match the behavior of the builtin objectives from the C++ side?

Motivation

Over the years of maintaining LightGBM, I've seen significant interest in implementing LightGBM's built-in objective functions in Python, for purposes like:

  • learning how LightGBM works (for people who are not comfortable with C++)
  • making it easier to measure the difference between custom objectives and LightGBM builtin ones
    • (e.g. if you have a Python function that exactly matches the builtin, then you can modify it and know any performance differences are due to your modifications)

See "References" for evidence.

Description

I am NOT proposing adding such implementations to any library that we publish.

Instead, I'm thinking of something like the following:

  • new directory in examples/ containing these implementations
  • tests that run in CI which compare the results to those calculated by the C++ side
  • those implementations accounting for the main concerns that confuse people:
    • calculating an init_score if Dataset doesn't have one
    • correctly using sample weights
    • correctly respecting boost_from_average

Things that do not necessarily need to be in scope for the first versions of implementations:

  • distributed training / collective operations
  • respect for deterministic parameter
  • anything related to quantized training
  • exact numerical precision (being within, say, 1e-6, would probably good enough to start)

References

GitHub posts that could be summarized as "how do I replicate a built-in LightGBM objective in Python"?

And Stack Overflow:

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions