lightgbm.train
- lightgbm.train(params, train_set, num_boost_round=100, valid_sets=None, valid_names=None, feval=None, init_model=None, keep_training_booster=False, callbacks=None)[source]
Perform the training with given parameters.
- Parameters:
params (dict) – Parameters for training. Values passed through
params
take precedence over those supplied via arguments.train_set (Dataset) – Data to be trained on.
num_boost_round (int, optional (default=100)) – Number of boosting iterations.
valid_sets (list of Dataset, or None, optional (default=None)) – List of data to be evaluated on during training.
valid_names (list of str, or None, optional (default=None)) – Names of
valid_sets
.feval (callable, list of callable, or None, optional (default=None)) –
Customized evaluation function. Each evaluation function should accept two parameters: preds, eval_data, and return (eval_name, eval_result, is_higher_better) or list of such tuples.
- predsnumpy 1-D array or numpy 2-D array (for multi-class task)
The predicted values. For multi-class task, preds are numpy 2-D array of shape = [n_samples, n_classes]. If custom objective function is used, predicted values are returned before any transformation, e.g. they are raw margin instead of probability of positive class for binary task in this case.
- eval_dataDataset
A
Dataset
to evaluate.- eval_namestr
The name of evaluation function (without whitespaces).
- eval_resultfloat
The eval result.
- is_higher_betterbool
Is eval result higher better, e.g. AUC is
is_higher_better
.
To ignore the default metric corresponding to the used objective, set the
metric
parameter to the string"None"
inparams
.init_model (str, pathlib.Path, Booster or None, optional (default=None)) – Filename of LightGBM model or Booster instance used for continue training.
keep_training_booster (bool, optional (default=False)) – Whether the returned Booster will be used to keep training. If False, the returned value will be converted into _InnerPredictor before returning. This means you won’t be able to use
eval
,eval_train
oreval_valid
methods of the returned Booster. When your model is very large and cause the memory error, you can try to set this param toTrue
to avoid the model conversion performed during the internal call ofmodel_to_string
. You can still use _InnerPredictor asinit_model
for future continue training.callbacks (list of callable, or None, optional (default=None)) – List of callback functions that are applied at each iteration. See Callbacks in Python API for more information.
Note
A custom objective function can be provided for the
objective
parameter. It should accept two parameters: preds, train_data and return (grad, hess).- predsnumpy 1-D array or numpy 2-D array (for multi-class task)
The predicted values. Predicted values are returned before any transformation, e.g. they are raw margin instead of probability of positive class for binary task.
- train_dataDataset
The training dataset.
- gradnumpy 1-D array or numpy 2-D array (for multi-class task)
The value of the first order derivative (gradient) of the loss with respect to the elements of preds for each sample point.
- hessnumpy 1-D array or numpy 2-D array (for multi-class task)
The value of the second order derivative (Hessian) of the loss with respect to the elements of preds for each sample point.
For multi-class task, preds are numpy 2-D array of shape = [n_samples, n_classes], and grad and hess should be returned in the same format.
- Returns:
booster – The trained Booster model.
- Return type: