UserWarning appears when using "early_stopping_rounds" and "verbose_eval" in python lightgbm

question:

UserWarning appears after calling the lightgbm library, setting the "early_stopping_rounds" parameter and the print log interval "verbose_eval" parameter

The sample code is as follows:

import lightgbm

cv_results = lightgbm.cv(
                    params,
                    lgb_train,
                    seed=1,
                    nfold=5,
                    metrics='auc',
                    ###
                    early_stopping_rounds=30, 
                    verbose_eval=True 
                    ###
                    )        

The two UserWarning are as follows:

UserWarning: 'early_stopping_rounds' argument is deprecated and will be removed in a future release of LightGBM. Pass 'early_stopping()' callback via 'callbacks' argument instead.

UserWarning: 'verbose_eval' argument is deprecated and will be removed in a future release of LightGBM. Pass 'log_evaluation()' callback via 'callbacks' argument instead.

reason:

' early_stopping_rounds ' argument is deprecated and will be removed in a future release of LightGBM. Pass ' early_stopping ( ) ' callback via 'callbacks' argument instead. delete. Pass in "early_stopping()" via the "callbacks" parameter instead.

Since the LightGBM library has changed the functions of the old version after the update, the parameters that need to be passed in or the way of passing in the parameters have changed.

Solution:

Modify the code as follows

import lightgbm

###
from lightgbm import log_evaluation, early_stopping
callbacks = [log_evaluation(period=100), early_stopping(stopping_rounds=30)]
###

cv_results = lightgbm.cv(
                    params,
                    lgb_train,
                    seed=1,
                    nfold=5,
                    metrics='auc',
                    ###
                    callbacks=callbacks
                    ###
                    )

first

from lightgbm import log_evaluation, early_stopping

use later

callbacks = [log_evaluation(period=100), early_stopping(stopping_rounds=30)]

Just replace the previous 'verbose_eval' and 'early_stopping_rounds' :)

Among them, period=100 means that the log is printed every 100 iterations; stopping_rounds=30 means that if the error of the verification set does not decrease within 30 iterations, the iteration is stopped.

Guess you like

Origin blog.csdn.net/weixin_51723388/article/details/124578560