LightGBM: Add decision_leaf output support#757
Draft
Copilot wants to merge 2 commits into
Draft
Conversation
Co-authored-by: xadupre <22452781+xadupre@users.noreply.github.com>
|
Copilot
AI
changed the title
[WIP] Add support for outputting decision path and leaf in LightGBM
LightGBM: Add Feb 23, 2026
decision_leaf output support
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
LightGBM's
predict(X, pred_leaf=True)has no ONNX equivalent — the converter had no mechanism to output which leaf node each sample reached per tree.Approach
Adds a
decision_leaf=Falseparameter to the converter. WhenTrue, a secondTreeEnsembleRegressornode is generated alongside the main prediction node, configured to output the sequential leaf index per tree (cast toint64). This avoids modifying the existing prediction graph and keeps the two concerns independent.Output shape:
[N, n_trees], dtypeint64.Changes
convert/main.py+lightgbm/convert.py: Exposedecision_leafon the publicconvert_lightgbm()API and thread it through toparse_lightgbm()lightgbm/_parse.py: Propagatedecision_leafthrough parse functions; attach it to the operator and append aleaf_indicesoutput variable when enabled; fixLgbmZipMapto only receive the first two outputs (label + probs) as inputslightgbm/operator_converters/LightGbm.py: Add_add_decision_leaf_output()— buildstarget_*attrs fromclass_treeids/class_nodeids, assigns one output column per tree (n_targets = n_trees), and casts float output to int64; fix regressor branch to useoperator.outputs[0].full_nameinstead ofoperator.output_full_names(which would incorrectly include leaf_indices)Classifier.py,Regressor.py,Ranker.py): Accept the optional extra output; setInt64TensorType([N, n_trees])whendecision_leaf=Truetests/lightgbm/test_lightgbm_decision_leaf.py: Tests for binary classifier, multiclass classifier, regressor, and the default no-leaf caseUsage
Original prompt
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.