0% found this document useful (0 votes)
99 views3 pages

LGB CV

This function performs cross-validation with given LightGBM parameters. It takes in the parameters, training data, number of boosting rounds, fold generation options, evaluation metrics, and other options. It returns a dictionary of evaluation histories for each metric, including the mean and standard deviation for each round. It can also optionally return the trained boosters from each fold.

Uploaded by

Bruce Tang
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
99 views3 pages

LGB CV

This function performs cross-validation with given LightGBM parameters. It takes in the parameters, training data, number of boosting rounds, fold generation options, evaluation metrics, and other options. It returns a dictionary of evaluation histories for each metric, including the mean and standard deviation for each round. It can also optionally return the trained boosters from each fold.

Uploaded by

Bruce Tang
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Signature:

lgb.cv(

params,

train_set,

num_boost_round=100,

folds=None,

nfold=5,

stratified=True,
shuffle=True,

metrics=None,

fobj=None,

feval=None,

init_model=None,

feature_name='auto',

categorical_feature='auto',

early_stopping_rounds=None,

fpreproc=None,

verbose_eval=None,

show_stdv=True,

seed=0,

callbacks=None,

eval_train_metric=False,

return_cvbooster=False,

Docstring:

Perform the cross-validation with given paramaters.

Parameters

----------

params : dict

Parameters for Booster.

train_set : Dataset

Data to be trained on.

num_boost_round : int, optional (default=100)

Number of boosting iterations.

folds : generator or iterator of (train_idx, test_idx) tuples, scikit-learn splitter object or None, optional (default=None)

If generator or iterator, it should yield the train and test indices for each fold.

If object, it should be one of the scikit-learn splitter classes

(https://scikit-learn.org/stable/modules/classes.html#splitter-classes)

and have ``split`` method.

This argument has highest priority over other data split arguments.

nfold : int, optional (default=5)

Number of folds in CV.

stratified : bool, optional (default=True)

Whether to perform stratified sampling.

shuffle : bool, optional (default=True)

Whether to shuffle before splitting data.

metrics : string, list of strings or None, optional (default=None)

Evaluation metrics to be monitored while CV.

If not None, the metric in ``params`` will be overridden.

fobj : callable or None, optional (default=None)

Customized objective function.

Should accept two parameters: preds, train_data,

and return (grad, hess).

preds : list or numpy 1-D array

The predicted values.

train_data : Dataset

The training dataset.

grad : list or numpy 1-D array

The value of the first order derivative (gradient) for each sample point.

hess : list or numpy 1-D array

The value of the second order derivative (Hessian) for each sample point.

For binary task, the preds is margin.

For multi-class task, the preds is group by class_id first, then group by row_id.

If you want to get i-th row preds in j-th class, the access way is score[j * num_data + i]

and you should group grad and hess in this way as well.

feval : callable, list of callable functions or None, optional (default=None)

Customized evaluation function.

Each evaluation function should accept two parameters: preds, train_data,

and return (eval_name, eval_result, is_higher_better) or list of such tuples.

preds : list or numpy 1-D array

The predicted values.

train_data : Dataset

The training dataset.

eval_name : string

The name of evaluation function (without whitespaces).

eval_result : float

The eval result.

is_higher_better : bool

Is eval result higher better, e.g. AUC is ``is_higher_better``.

For binary task, the preds is probability of positive class (or margin in case of specified ``fobj``).

For multi-class task, the preds is group by class_id first, then group by row_id.

If you want to get i-th row preds in j-th class, the access way is preds[j * num_data + i].

To ignore the default metric corresponding to the used objective,

set ``metrics`` to the string ``"None"``.

init_model : string, Booster or None, optional (default=None)

Filename of LightGBM model or Booster instance used for continue training.

feature_name : list of strings or 'auto', optional (default="auto")

Feature names.

If 'auto' and data is pandas DataFrame, data columns names are used.

categorical_feature : list of strings or int, or 'auto', optional (default="auto")


Categorical features.

If list of int, interpreted as indices.

If list of strings, interpreted as feature names (need to specify ``feature_name`` as well).

If 'auto' and data is pandas DataFrame, pandas unordered categorical columns are used.

All values in categorical features should be less than int32 max value (2147483647).

Large values could be memory consuming. Consider using consecutive integers starting from zero.

All negative values in categorical features will be treated as missing values.

The output cannot be monotonically constrained with respect to a categorical feature.

early_stopping_rounds : int or None, optional (default=None)

Activates early stopping.

CV score needs to improve at least every ``early_stopping_rounds`` round(s)

to continue.

Requires at least one metric. If there's more than one, will check all of them.

To check only the first metric, set the ``first_metric_only`` parameter to ``True`` in ``params``.

Last entry in evaluation history is the one from the best iteration.

fpreproc : callable or None, optional (default=None)

Preprocessing function that takes (dtrain, dtest, params)

and returns transformed versions of those.

verbose_eval : bool, int, or None, optional (default=None)

Whether to display the progress.

If None, progress will be displayed when np.ndarray is returned.

If True, progress will be displayed at every boosting stage.

If int, progress will be displayed at every given ``verbose_eval`` boosting stage.

show_stdv : bool, optional (default=True)

Whether to display the standard deviation in progress.

Results are not affected by this parameter, and always contain std.

seed : int, optional (default=0)

Seed used to generate the folds (passed to numpy.random.seed).

callbacks : list of callables or None, optional (default=None)

List of callback functions that are applied at each iteration.

See Callbacks in Python API for more information.

eval_train_metric : bool, optional (default=False)

Whether to display the train metric in progress.

The score of the metric is calculated again after each training step, so there is some impact on performance.

return_cvbooster : bool, optional (default=False)

Whether to return Booster models trained on each fold through ``CVBooster``.

Returns

-------

eval_hist : dict

Evaluation history.

The dictionary has the following format:

{'metric1-mean': [values], 'metric1-stdv': [values],

'metric2-mean': [values], 'metric2-stdv': [values],

...}.

If ``return_cvbooster=True``, also returns trained boosters via ``cvbooster`` key.

File: e:\anaconda\installation\lib\site-packages\lightgbm\engine.py

Type: function

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy