Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable init_score for random forest boosting #6652

Open
bili2002 opened this issue Sep 13, 2024 · 2 comments
Open

Enable init_score for random forest boosting #6652

bili2002 opened this issue Sep 13, 2024 · 2 comments
Labels

Comments

@bili2002
Copy link
Contributor

Summary

Currently, providing init_score to random forest training produces an error. After independent testing I have concluded that a fix is pretty straight forward.

Is there some hidden problem I am missing or should I submit a PR to comment on?

@jameslamb
Copy link
Collaborator

Please provide a minimum, reproducible example that shows evidence of the "bug". This link to a line of code is not enough evidence on its own.

@bili2002
Copy link
Contributor Author

Here is an example:

import lightgbm as lgb
import numpy as np
import sklearn.datasets

X, y = sklearn.datasets.load_breast_cancer(return_X_y=True)

params = {
    "boosting_type": "rf",
    "objective": "binary",
    "bagging_freq": 1,
    "bagging_fraction": 0.5,
    "feature_fraction": 0.5,
    "num_leaves": 50,
    "metric": "binary_logloss",
    "verbose": -1,
}

print(
    lgb.train(
        params, lgb.Dataset(X, y, init_score=np.full(len(X), 0)), num_boost_round=50
    ).predict(X)
)

The code produces the following error:

[LightGBM] [Fatal] Check failed: (train_data->metadata().init_score()) == (nullptr) at /Users/runner/miniforge3/conda-bld/lightgbm_1726154828439/work/src/boosting/rf.hpp, line 48 .

Traceback (most recent call last):
  File "/Users/bilyanaindzheva/work/test.py", line 19, in <module>
    lgb.train(
  File "/Users/bilyanaindzheva/miniforge3/envs/test1/lib/python3.12/site-packages/lightgbm/engine.py", line 282, in train
    booster = Booster(params=params, train_set=train_set)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/bilyanaindzheva/miniforge3/envs/test1/lib/python3.12/site-packages/lightgbm/basic.py", line 3641, in __init__
    _safe_call(
  File "/Users/bilyanaindzheva/miniforge3/envs/test1/lib/python3.12/site-packages/lightgbm/basic.py", line 296, in _safe_call
    raise LightGBMError(_LIB.LGBM_GetLastError().decode("utf-8"))
lightgbm.basic.LightGBMError: Check failed: (train_data->metadata().init_score()) == (nullptr) at /Users/runner/miniforge3/conda-bld/lightgbm_1726154828439/work/src/boosting/rf.hpp, line 48 .

When boosting_type is gdbt the code executes correctly. Also, when init_score is not set then there is no error as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants