You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Starting with scikit-learn 1.6 (I think), lightgbm.sklearn estimators emit this warning in predict(), even when the data passed to fit() did not have feature names (e.g. was just a numpy array):
/Users/jlamb/miniforge3/envs/lgb-dev/lib/python3.11/site-packages/sklearn/utils/validation.py:2739: UserWarning: X does not have valid feature names, but LGBMClassifier was fitted with feature names
warnings.warn(
This is confusing. Either:
lightgbm shouldn't raise this warning in situations where the input data did not have feature names but LightGBM automatically generated them.
I think that what's happening here is that scikit-learn will always say that the model "was fitted with feature names" because LightGBM automatically assigns feature names of the form Column_0, Column_1, etc..
Description
Starting with
scikit-learn
1.6 (I think),lightgbm.sklearn
estimators emit this warning inpredict()
, even when the data passed tofit()
did not have feature names (e.g. was just anumpy
array):This is confusing. Either:
lightgbm
shouldn't raise this warning in situations where the input data did not have feature names but LightGBM automatically generated them.Reproducible example
This is sufficient to produce the warning.
It is also showing up in CI logs, for example: https://github.com/microsoft/LightGBM/actions/runs/12922031182/job/36037058867#step:3:6864
I think that what's happening here is that
scikit-learn
will always say that the model "was fitted with feature names" because LightGBM automatically assigns feature names of the formColumn_0, Column_1, etc.
.LightGBM/python-package/lightgbm/sklearn.py
Line 1246 in 3654eca
Environment info
LightGBM version or commit hash: 3654eca
Command(s) you used to install LightGBM
cmake -B build -S . cmake --build build --target _lightgbm sh build-python.sh install --precompile
Additional Comments
Here's where the warning comes from in
scikit-learn
:https://github.com/scikit-learn/scikit-learn/blob/e44742ea6c06ee891e92facb886f268f7cfc033b/sklearn/utils/validation.py#L2736-L2741
Any solution to this should comply with all of the expectations for
scikit-learn
estimators at https://scikit-learn.org/stable/developers/develop.htmlThe text was updated successfully, but these errors were encountered: