问题
I have tried the following simple code:
import lightgbm, pandas
params = {'objective': 'multiclass', 'num_classes': 4}
train_df = pandas.DataFrame({'f0': [0, 1, 2, 3] * 5, 'f1': [0, 0, 1] * 6 + [1, 2]}, dtype=float)
train_target = pandas.Series([0, 1, 2, 3] * 5)
train_set = lightgbm.Dataset(train_df, train_target)
model = lightgbm.train(params=params, train_set=train_set)
The output is as follows:
[LightGBM] [Warning] There are no meaningful features, as all feature values are constant.
[LightGBM] [Info] Total Bins 0
[LightGBM] [Info] Number of data: 20, number of used features: 0
[LightGBM] [Info] Start training from score -1.386294
[LightGBM] [Info] Start training from score -1.386294
[LightGBM] [Info] Start training from score -1.386294
[LightGBM] [Info] Start training from score -1.386294
[LightGBM] [Warning] Stopped training because there are no more leaves that meet the split requirements
My features are clearly not constant.
What is wrong?
I am running Python 3.5.2 on Ubuntu 16.04.
回答1:
I figured it out.
The problem is that the default value of min_data_in_leaf
is 20, and I did not change it.
My data have only 20 rows. For this reason, LightGBM reported that it could not split it as the minimum number of samples in each split is 20.
(In fact, it did not need to split it as the solution is one tree having only one leaf. But apparently LightGBM is checking for the possibility of a split anyway.)
I increased the number of rows and LightGBM trained fine.
来源:https://stackoverflow.com/questions/58708090/lightgbm-warning-there-are-no-meaningful-features-as-all-feature-values-are-co