Skip to content

[R-package]: add num_trees_per_iter, num_trees, and num_iter methods#6500

Merged
jameslamb merged 4 commits intomicrosoft:masterfrom
mayer79:expose_num_trees
Jul 3, 2024
Merged

[R-package]: add num_trees_per_iter, num_trees, and num_iter methods#6500
jameslamb merged 4 commits intomicrosoft:masterfrom
mayer79:expose_num_trees

Conversation

@mayer79
Copy link
Contributor

@mayer79 mayer79 commented Jun 21, 2024

This PR adds to the R Booster class the following methods:

  • num_trees_per_iter(),
  • num_trees(), and
  • num_iter()

Two functions from the C API are required:

  • LGBM_BoosterNumModelPerIteration_R() via LGBM_BoosterNumModelPerIteration() and
  • LGBM_BoosterNumberOfTotalModel_R() via LGBM_BoosterNumberOfTotalModel()

This additionally helps to solve #6380.

Note: With early stopping, the number of (relevant) iterations is kept in Booster$best_iter, while num_trees() and num_iter() are higher.

Copy link
Collaborator

@jameslamb jameslamb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks very much! I support adding these methods on the Booster and not also adding new exported functions for them. And the tests look great.

Will you please just consider my recommendation to use the language "trees" instead of "models"?

@mayer79 mayer79 changed the title [R-package]: add num_models_per_iter, num_total_models, and num_iter methods [R-package]: add num_trees_per_iter, num_trees, and num_iter methods Jun 22, 2024
Copy link
Collaborator

@jameslamb jameslamb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great, thank you!

@jmoralez do you have time to also review this week? I'd like to hear your opinion on adding this to the R package's public API.

@jameslamb
Copy link
Collaborator

Thanks @jmoralez ! I'll look into the failing CI and merge this.

@jameslamb jameslamb merged commit 7d9106d into microsoft:master Jul 3, 2024
@github-actions
Copy link
Contributor

This pull request has been automatically locked since there has not been any recent activity since it was closed.
To start a new related discussion, open a new issue at https://github.com/microsoft/LightGBM/issues including a reference to this.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 10, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants