lightgbm.CVBooster
- class lightgbm.CVBooster(model_file=None)[source]
Bases:
object
CVBooster in LightGBM.
Auxiliary data structure to hold and redirect all boosters of
cv()
function. This class has the same methods as Booster class. All method calls, except for the following methods, are actually performed for underlying Boosters and then all returned results are returned in a list.model_from_string()
model_to_string()
save_model()
- best_iteration
The best iteration of fitted model.
- Type:
int
- __init__(model_file=None)[source]
Initialize the CVBooster.
- Parameters:
model_file (str, pathlib.Path or None, optional (default=None)) – Path to the CVBooster model file.
Methods
__init__
([model_file])Initialize the CVBooster.
model_from_string
(model_str)Load CVBooster from a string.
model_to_string
([num_iteration, ...])Save CVBooster to JSON string.
save_model
(filename[, num_iteration, ...])Save CVBooster to a file as JSON text.
- model_from_string(model_str)[source]
Load CVBooster from a string.
- Parameters:
model_str (str) – Model will be loaded from this string.
- Returns:
self – Loaded CVBooster object.
- Return type:
- model_to_string(num_iteration=None, start_iteration=0, importance_type='split')[source]
Save CVBooster to JSON string.
- Parameters:
num_iteration (int or None, optional (default=None)) – Index of the iteration that should be saved. If None, if the best iteration exists, it is saved; otherwise, all iterations are saved. If <= 0, all iterations are saved.
start_iteration (int, optional (default=0)) – Start index of the iteration that should be saved.
importance_type (str, optional (default="split")) – What type of feature importance should be saved. If “split”, result contains numbers of times the feature is used in a model. If “gain”, result contains total gains of splits which use the feature.
- Returns:
str_repr – JSON string representation of CVBooster.
- Return type:
str
- save_model(filename, num_iteration=None, start_iteration=0, importance_type='split')[source]
Save CVBooster to a file as JSON text.
- Parameters:
filename (str or pathlib.Path) – Filename to save CVBooster.
num_iteration (int or None, optional (default=None)) – Index of the iteration that should be saved. If None, if the best iteration exists, it is saved; otherwise, all iterations are saved. If <= 0, all iterations are saved.
start_iteration (int, optional (default=0)) – Start index of the iteration that should be saved.
importance_type (str, optional (default="split")) – What type of feature importance should be saved. If “split”, result contains numbers of times the feature is used in a model. If “gain”, result contains total gains of splits which use the feature.
- Returns:
self – Returns self.
- Return type: