Skip to content Skip to sidebar Skip to footer

How To Use Lightgbm.cv For Regression?

I want to do a cross validation for LightGBM model with lgb.Dataset and use early_stopping_rounds. The following approach works without a problem with XGBoost's xgboost.cv. I prefe

Solution 1:

By default, the stratify parameter in the lightgbm.cv is True. According to the documentation:

stratified (bool, optional (default=True)) – Whether to perform stratified sampling.

But stratify works only with classification problems. So to work with regression, you need to make it False.

cv_results = lgb.cv(
        params,
        dftrainLGB,
        num_boost_round=100,
        nfold=3,
        metrics='mae',
        early_stopping_rounds=10,

        # This is what I added
        stratified=False
        )

Now its working.

Post a Comment for "How To Use Lightgbm.cv For Regression?"