LightGBM icon indicating copy to clipboard operation
LightGBM copied to clipboard

unexpected Behavior of dropout in poisson regression

Open DeppLearning opened this issue 9 years ago • 16 comments

I understand that with 1000 rounds, drop rate= 0.001,skip_drop = 0 and max_drop = 1, I should expect to see about 1 tree drop out. Is this correct?

I'm attempting to tune several lightgbms on grouped data (1 lgb per group). For most of my groups, drop out seems to help and improves my predictions by say 5%. However, for one of my groups, dropping even a (supposably) single tree (of hundreds) completely ruins the prediction with increases of the error up to 300%.

When I set the drop_rate to 0.2 (leaving all other drop out related parameters at default) the model won't even finish computing in many times after waiting for 10x the runtime I get without dropout.

Enabling uniform_dropout only makes it worse (by ~ 10^40)

Setting objective from poisson to regression helps tremendously..

Without dropout, I get very good predictions for that group as well as for the other groups.

Unfortunatelly I can't share the data in public, but only in private, please let me know how to do so.

I'm very glad for any help

I am using the latest version of the R package

DeppLearning avatar Sep 05 '17 10:09 DeppLearning

@henry0312

guolinke avatar Sep 07 '17 04:09 guolinke

I'm so sorry for late response, but I don't know the cause of your issue. Did you try the latest version of LightGBM?

I understand that with 1000 rounds, drop rate= 0.001,skip_drop = 0 and max_drop = 1, I should expect to see about 1 tree drop out. Is this correct?

This may be wrong. The expected number of trees to be dropped is 1 (sometimes 0 or 2...).

henry0312 avatar Sep 20 '17 03:09 henry0312

Does the same group always have terible score with different seed?

marugari avatar Sep 22 '17 07:09 marugari

sorry for my late response:

Did you try the latest version of LightGBM?

Yes I tried the newest version of lightGBM with working poisson regression (so after it was fixed) and also tried by building again from the master branch right before I made this posting.

The expected number of trees to be dropped is 1 ,

thats what I meant with „, I should expect to see..“, sorry for beeing unclear here.

Does the same group always have terible score with different seed?

Alot of the times yes. Even when I try to set up the parameters like I posted, so trying to achieve that only a handful of trees may be dropped out(out of at least 300), it goes wrong. I guess it won't fail for only this group, it's just one that is very important to me and is usually one that is easy to fit. Of all my groups, this is probaly the one which is least poisson-distributed and more normally distributed than the others.

I guess the issue relates to the poisson objective and exploding gradients, as the margin of error I get is comparable to the one I got using poisson objective before it was actually fixed.

DeppLearning avatar Sep 25 '17 09:09 DeppLearning

@weltherrschaf Can you define a custom Poisson loss function and cap the range of gradients/hessians so they don't explode, then test again if you see the sudden metric jumps?

You can find the formulas here: https://github.com/Microsoft/LightGBM/blob/master/src/objective/regression_objective.hpp#L298-L364

Laurae2 avatar Oct 01 '17 19:10 Laurae2

@Laurae2 I tried but didn't get too far. First I tried to replicate/approximate my results from using the poisson objective WITHOUT dart. However, only some of the predictions are comparable, the rest is way off. This is the objective I used:

` poissonregobj <- function(preds, dtrain) {

  labels <- getinfo(dtrain, "label")

  preds <-exp(preds)

  grad <- preds - labels

  hess <- preds

  return(list(grad = grad, hess = hess))
}`

Any tips on how to set it up in a way that gives me comparable results to the original poisson objective?

DeppLearning avatar Oct 04 '17 15:10 DeppLearning

@weltherrschaf These are the following formulas, like you did:

  • Gradient: exp(pred) - labels
  • Hessian: exp(pred)

Exact reproducibility of results is not guaranteed as there may be decimal precision differences vs C++.

Laurae2 avatar Oct 21 '17 08:10 Laurae2

Does it work better if you enable "boost_from_average"? This is supposed to start the boosting from a better initial score w.r.t. the given labels.

Also, can you create a toy poisson regression problem where you know the exact solution and test on that?

olofer avatar Oct 21 '17 13:10 olofer

@weltherrschaf Any news?

Laurae2 avatar Nov 14 '17 19:11 Laurae2

Sorry for taking so long, I'm still experiencing a bunch of issues, however, they grow more chaotic and it get's harder for me to pin them down. So let's start one by one

Exact reproducibility of results is not guaranteed as there may be decimal precision differences vs C++.

these were differences too big for decimal precision differences I guess, as the values differed by a factor of ~20.

Does it work better if you enable "boost_from_average"?`

Unfortunatelly not, thanks for the suggestion.

My original issue was that using DART in poisson models seemed to lead to exploding gradients. Since the model performed very well with gbdt, I sticked to that. This code reproduces the error on my maschine, with the lgb R package that I'm successfully using in production for poisson models. I tried to set it up, so that we expect to see one tree dropped, might not drop every time though. In that version it looked like the poisson exploding gradient issue was solved for gbdt, however, if I apply dart, I'll get exploding gradients about every 2nd time.

n = 10000 xreg = data.matrix(data.frame(c1 = rnorm(n), c2 = rnorm(n), g = as.factor(rpois(n, 0.5)))) y = apply(xreg,1,FUN = function(x) rpois(1,abs(sum(as.numeric(x),na.rm=T))))

data <- lightgbm::lgb.Dataset(data = xreg, label = y,categorical_feature =3 )

seed = as.numeric(Sys.time())

params = list( learning_rate = 0.3 ,lambda_l1 = 1.0 ,lambda_l2 = 0.1 ,objective = "poisson"

,max_bin = 255L ,num_leaves =10L ,min_data_in_leaf= 1L ,min_sum_hessian_in_leaf = 1L ,max_depth = -1L ,boosting = "dart" ,drop_rate = 0.001 ,max_drop = 1 ,drop_seed = seed

)

model <- lightgbm::lightgbm(data,params = params,nrounds = 1000, verbose = -1) fit <- predict(model,data =xreg) print(mean(abs( (fit[y>0]-y[y>0]) / y[y>0]),na.rm=T))

I'm using the stable release that I downloaded and installed on 08.11.2017. I can only reproduce the error with that version. If I repeat the whole process today on any maschine, I seem to be getting a different R package. Even if I use that very source files. Same Version number, but different behavior: The example I provided, won't give strange results, but the model I'm running in production will explode again when used with the poisson objective. I suspect, in that version it's the predict functions, as I'm using early_stopping during fitting, and I'm getting a comparable number of trees fit, even from models from which I get the exploded predictions.

Again, I'm willing to share the data, basically anything needed to reproduce the issue on your maschine in private, just let me know how.

For me and my team, more explicit R-package version numbers would help alot.

I guess there is no way, to make my cherished version of the lgb package run on linux (Ubuntu 16.x, centos 7.x ) so I can use my original setup there?

DeppLearning avatar Nov 16 '17 09:11 DeppLearning

This code reproduces the error on my maschine, with the lgb R package that I'm successfully using in production for poisson models. I tried to set it up, so that we expect to see one tree dropped, might not drop every time though. In that version it looked like the poisson exploding gradient issue was solved for gbdt, however, if I apply dart, I'll get exploding gradients about every 2nd time.

@guolinke Do we have the limitation on the gradient values with DART booster when using Poisson regression?

I guess there is no way, to make my cherished version of the lgb package run on linux (Ubuntu 16.x, centos 7.x ) so I can use my original setup there?

If both machines are using R, you can just copy and paste the package. It works as long as you don't put the package in a Windows machine.

Laurae2 avatar Nov 22 '17 19:11 Laurae2

@Laurae2 I think the DART just random drop trees.

guolinke avatar Nov 23 '17 03:11 guolinke

@Laurae2 I think the DART just random drop trees.

uniform_drop, default=false, type=bool xgboost_dart_mode, default=false, type=bool

when I originally encountered the problem, I tried manipulating these params with no success though. From what I inferred from the doc, DART should drop trees depending on their weight.

If both machines are using R, you can just copy and paste the package. It works as long as you don't put the package in a Windows machine.

Unfortunatelly it was compiled on a windows machine

Despite the issues I'm having, thank you all for providing this amazing package to the R-community

DeppLearning avatar Nov 28 '17 13:11 DeppLearning

@weltherrschaf If you use Windows, look at the date of the folder of lightgbm in your R libraries. From there, you know which date to look up on this repository to fetch the specific commit you need for installing the cherished version of LightGBM you are using.

Also, with your code, no issue after running it 100 times:

n <- 10000
xreg <- data.matrix(data.frame(c1 = rnorm(n), c2 = rnorm(n), g = as.factor(rpois(n, 0.5))))
y <- apply(xreg, 1, FUN = function(x) rpois(1,abs(sum(as.numeric(x), na.rm = TRUE))))

data <- lightgbm::lgb.Dataset(data = xreg, label = y,categorical_feature =3 )

seed <- as.numeric(Sys.time())

params <- list(learning_rate = 0.3,
               lambda_l1 = 1.0,
               lambda_l2 = 0.1,
               objective = "poisson",
               nthread = 1,
               max_bin = 255L,
               num_leaves = 10L,
               min_data_in_leaf= 1L,
               min_sum_hessian_in_leaf = 1L,
               max_depth = -1L,
               boosting = "dart",
               drop_rate = 0.001,
               max_drop = 1,
               drop_seed = seed)

model <- lightgbm::lightgbm(data,
                            params = params,
                            nrounds = 1000,
                            verbose = -1)
fit <- predict(model,data = xreg)
print(mean(abs((fit[y > 0] - y[y > 0]) / y[y > 0]), na.rm = TRUE))

I suspect you will need to make the threshold of gradients on the model you are trying to train for production, use poisson_max_delta_step lower than 0.7 (ex: use 0.1), but this will also make training slower. Poisson regression can be unstable with the 0.7 threshold, DART should make it even more unstable if it drops a "bad luck" tree.

Laurae2 avatar Dec 25 '17 10:12 Laurae2

@weltherrschaf the problem is running very slow when enable drop-out with poisson ? the slow is the time for the same iteration? or the time to convergence ?

guolinke avatar Dec 29 '17 01:12 guolinke

close since there is not response, @weltherrschaf feel free to reopen.

guolinke avatar Apr 30 '18 23:04 guolinke