Search code examples
binaryclassificationlightgbmauccross-entropy

Does LightGBM binary classifier with (AUC-based) early-stopping rounds take log loss as objective function, or use AUC in optimization algorithm?


I have a LightGBM gradient boosting model for a binary classification task. The LightGBM parameters specification state that the objective function of binary classification is the log loss (cross entropy). Hence, I understand that is the objective function the model uses in its optimization.

However, I have set up the model to stop training if the AUC on the validation data doesn’t improve after 10 rounds. Now, has the objective function of the algorithm changed to one based on the AUC, or did it remain as before, and merely calculating the AUCs in parallel on the validation set to check if scores don't improve after 10 rounds?

For reference, my code below:

model = lightgbm.LGBMClassifier(n_estimators=500, learning_rate=0.01)
fit_params={"early_stopping_rounds":30,
                "eval_metric" : 'auc',
                "eval_set" : [(X_test,y_test)],
                'eval_names': ['valid'],
                #'callbacks': [lgb.reset_parameter(learning_rate=learning_rate_010_decay_power_099)],
                'verbose': 100,
                'categorical_feature': 'auto'}

params = { 'boosting': ['gbdt'],
        'objective': ['binary'],
        'num_leaves': sp_randint(20, 63), # adjust to inc AUC
        'max_depth': sp_randint(3, 8),
        'min_child_samples': sp_randint(100, 500),
        'min_child_weight': [1e-5, 1e-3, 1e-2, 1e-1, 1, 1e1, 1e2, 1e3, 1e4],
        'subsample': sp_uniform(loc=0.2, scale=0.8),
        'colsample_bytree': sp_uniform(loc=0.4, scale=0.6),
        'reg_alpha': [0, 1e-1, 1, 2, 5, 7, 10, 50, 100],
        'reg_lambda': [0, 1e-1, 1, 5, 10, 20, 50, 100],
        'is_unbalance': ['true'],
        'feature_fraction': np.arange(0.3, 0.6, 0.05), # model trained faster AND prevents overfitting
        'bagging_fraction': np.arange(0.3, 0.6, 0.05), # similar benefits as above
        'bagging_freq': np.arange(10, 30, 5),  # after every 20 iterations, lgb will randomly select 50% of observations and use it for next 20 iterations
        }
RSCV = RandomizedSearchCV(model, params, scoring= 'roc_auc', cv=3, n_iter=10, refit=True, random_state=42, verbose=True)
RSCV.fit(X_train, y_train, **fit_params)

Solution

  • The objective remains log-loss.

    I don't have a good way to demonstrate this. But AUC cannot easily be used as an objective function, since it only care about the ordering of the predictions; it wouldn't by itself be able to push predictions toward particular values.