LightGBM icon indicating copy to clipboard operation
LightGBM copied to clipboard

How to encode categorical features

Open nlothian opened this issue 10 years ago • 8 comments

I have a libsvm file containing a mix of continuous and categorical features, and I'm attempting to use LambdaRank on it. Here is a sample:

0.0 1:0.142095914742 7:1.0 302:1.0
0.0 1:0.20207253886 397:1.0 979:1.0
0.0 1:0.243902439024 68:1.0
1.0 1:0.142095914742 7:1.0 302:1.0
0.0 1:0.0689655172414 318:1.0 397:1.0
0.0 1:0.047619047619 45:1.0 323:1.0 531:1.0

When I train, I get the following:

[LightGBM] [Warning] Ignoring feature Column_33307, only has one value [LightGBM] [Warning] Ignoring feature Column_33308, only has one value [LightGBM] [Warning] Ignoring feature Column_33309, only has one value [LightGBM] [Warning] Ignoring feature Column_33310, only has one value [LightGBM] [Warning] Ignoring feature Column_33311, only has one value

I think this means it is ignoring my categorical features. How am I supposed to encode them?

nlothian avatar Nov 08 '16 08:11 nlothian

its means that all of your sample have same value on these features, thus make these feature "unsplitable"

chivee avatar Nov 08 '16 08:11 chivee

The maximum feature index I have is 4082

0.0 1:0.0926002480364 3:1.0 18:1.0 308:1.0 4082:1.0

My error log starts like this:

[LightGBM] [Info] Loading query boundaries...
[LightGBM] [Warning] Ignoring feature Column_0, only has one value
[LightGBM] [Warning] Ignoring feature Column_4, only has one value
[LightGBM] [Warning] Ignoring feature Column_12, only has one value

Where are the column names coming from? I don't have a feature index 0

nlothian avatar Nov 08 '16 09:11 nlothian

@nlothian

  1. columns are ignored is because these columns only contain one value(like all zeros), or very sparse.
  2. What is the number of your data?
  3. The max index is really 4082 ? I see your log above are ignoring 30000+ features.
  4. The feature index in Libsvm start with 0 , and you data don't use this column. so it will be ignored.

guolinke avatar Nov 09 '16 01:11 guolinke

  1. I have 10,000 rows of data.
  2. Yes. This is one of the reasons I'm puzzled! I've attached my data and query file. Clearly I'm doing something wrong.

train.libsvm.zip train.libsvm.query.zip

.

nlothian avatar Nov 09 '16 04:11 nlothian

Hi, @nlothian , I found feature index '33937' in your data file. you can check in line 1894.

guolinke avatar Nov 09 '16 05:11 guolinke

Thanks @guolinke, my apologies - I missed it.

nlothian avatar Nov 09 '16 05:11 nlothian

however, this warning doesn't affect the training result.

chivee avatar Nov 09 '16 06:11 chivee

This issue 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[bot] avatar Aug 24 '23 04:08 github-actions[bot]