LightGBM icon indicating copy to clipboard operation
LightGBM copied to clipboard

Categorical features with missing values

Open rgranvil opened this issue 9 years ago • 1 comments

This is a simple example with a single categorical predictor x, a binary target y, and a model with a single split. It seems that the missing value direction is suboptimal in this case. I would expect the missing value to be grouped with levels 1, 2, and 3 instead of with levels 4 and 5. Is this the intended behavior?

image

Code:

library(lightgbm)
df <- data.frame(x = as.numeric(c(NA, 1:5)), y = c(1, 1, 1, 1, 0, 0))
str(df)
lgb.data <- lgb.Dataset(
  data = as.matrix(df["x"])
  ,label = df$y
  ,categorical_feature = "x")
lgb.model <- lgb.train(
  data = lgb.data
  ,obj = "binary"
  ,min_data = 1
  ,min_data_in_bin = 1
  ,num_leaves = 2
  ,nrounds = 1
  ,learning_rate = 1
)
df$Prediction <- predict(lgb.model, as.matrix(df["x"]))
df

rgranvil avatar Aug 16 '17 01:08 rgranvil

@rgranvil Thanks very much for many deep dives of these bugs.

guolinke avatar Aug 16 '17 02:08 guolinke