LightGBM icon indicating copy to clipboard operation
LightGBM copied to clipboard

Why not have binary classification initialize to the base rate by default?

Open zkurtz opened this issue 8 years ago • 6 comments

Currently, a logistic regression on unbalanced data evidently initializes the probability(TRUE) = 0.5 regardless of the base rate. For example, with a base rate of ~0.1 and a single boosting round with a low learning rate, the resulting scores are all very close to 0.5:

library(lightgbm)

# Simulate some data
set.seed(0)
n_samples = 10000
x1 = rnorm(n_samples)
x2 = rnorm(n_samples)
X = cbind(x1, x2)
binary_labels = rbinom(n_samples, size = 1, prob = 0.1)
train = lightgbm::lgb.Dataset(data = X, label = binary_labels)

# Fit a booster
bst = lightgbm::lgb.train(
    params = list(
        objective = "binary",
        learning_rate = 0.01
    ),
    data = train,
    nrounds = 1,
    verbose = 0)

# Fitted rate of label == 1:
fitted_values = predict(bst, X)
mean(fitted_values) # = 0.49598
# Base rate of label == 1:
mean(binary_labels) # = 0.0982

This is particularly problematic in small datasets where overfitting is an immediate concern. It means that the booster must be run a sufficient number of iterations at a sufficiently high learning rate just to learn the base rate even if fewer iterations at lower learning rate are sufficient to arrive at the "overfitting frontier". Is there any reason not to be initializing to the base rate instead of 0.5?

To be slightly more regularized, one could initialize to the Bayesian + uniform prior estimator of the base rate, biasing towards 0.5 slightly: (y + 1)/(n + 2) where y is the number of positive cases and n is the number of cases.

zkurtz avatar Apr 23 '18 15:04 zkurtz

@zkurtz we have BoostFromAverage (https://github.com/Microsoft/LightGBM/blob/master/src/boosting/gbdt.cpp#L353-L375), but only for regression now. I also tested it for binary classification cases. However, most of them don't have improvement (with enough iterations and early stopping), although it can speed up the convergence slightly. So I only added this for regression.

But you are right, it will have problems, when learning_rate is too small. In this case, you can use init_score to speed up.

Do you think this is needed for binary classification ? If you think it is needed, welcome to open a PR. You can override the BoostFromScore in Binary objective, similar to regression one(https://github.com/Microsoft/LightGBM/blob/381bc1228333070346d27a673dd76f252d2e3322/src/objective/regression_objective.hpp#L142-L159)

guolinke avatar Apr 24 '18 06:04 guolinke

Yes I think this would be an improvement for binary classification. I'll do some testing via init_score, which looks like it could achieve the desired behavior. If that works, I'll try to figure out how to modify the source code and do a PR -- this would be my first!

zkurtz avatar Apr 24 '18 14:04 zkurtz

You can achieve what you want already (unless I'm mistaken) by using the boost-from-average option with the xentropy objective.

olofer avatar Apr 24 '18 19:04 olofer

Thanks @olofer , the xentropy do support this.

guolinke avatar Apr 30 '18 23:04 guolinke

Indeed xentropy appears to be a workable solution. I still wonder if the default for binary should be updated. It's also not clear to me why there are separate xentropy and binary objectives when they appear to be the same in the case of labels in [0,1].

Notes for usage in R:

  • xentropy actually appears to have boost_from_average = TRUE by default, which is great.
  • The init_score option appears to be missing in the R-package, so it's not straightforward to test that xentropy and binary give equivalent results when both boost from the average.

zkurtz avatar May 01 '18 18:05 zkurtz

@zkurtz feel free to open a PR if you think it is needed to update the binary

guolinke avatar May 02 '18 08:05 guolinke