lightgbm.CVBooster

class lightgbm.CVBooster(model_file=None)[source]

基类: object

LightGBM 中的 CVBooster。

用于保存和重定向 cv() 函数所有 Booster 的辅助数据结构。此类具有与 Booster 类相同的公共方法。除了以下方法外,所有方法调用实际上都作用于底层的 Booster,然后所有返回结果都以列表形式返回。

  • model_from_string()

  • model_to_string()

  • save_model()

boosters

底层已拟合模型的列表。

类型:

Booster 列表

best_iteration

已拟合模型的最佳迭代次数。

类型:

int

__init__(model_file=None)[source]

初始化 CVBooster。

参数:

model_file (str, pathlib.Path or None, optional (default=None)) – CVBooster 模型文件的路径。

方法

__init__([model_file])

初始化 CVBooster。

model_from_string(model_str)

从字符串加载 CVBooster。

model_to_string([num_iteration, ...])

将 CVBooster 保存为 JSON 字符串。

save_model(filename[, num_iteration, ...])

将 CVBooster 保存到文件作为 JSON 文本。

model_from_string(model_str)[source]

从字符串加载 CVBooster。

参数:

model_str (str) – 模型将从该字符串加载。

返回:

self – 加载的 CVBooster 对象。

返回类型:

CVBooster

model_to_string(num_iteration=None, start_iteration=0, importance_type='split')[source]

将 CVBooster 保存为 JSON 字符串。

参数:
  • num_iteration (int or None, optional (default=None)) – 应保存的迭代次数索引。如果为 None,则如果存在最佳迭代次数,则保存该迭代次数;否则,保存所有迭代次数。如果 <= 0,则保存所有迭代次数。

  • start_iteration (int, optional (default=0)) – 应保存的迭代次数的起始索引。

  • importance_type (str, optional (default="split")) – 应保存的特征重要性类型。如果为 “split”,结果包含特征在模型中使用的次数。如果为 “gain”,结果包含使用该特征的分裂的总增益。

返回:

str_repr – CVBooster 的 JSON 字符串表示。

返回类型:

str

save_model(filename, num_iteration=None, start_iteration=0, importance_type='split')[source]

将 CVBooster 保存到文件作为 JSON 文本。

参数:
  • filename (str or pathlib.Path) – 保存 CVBooster 的文件名。

  • num_iteration (int or None, optional (default=None)) – 应保存的迭代次数索引。如果为 None,则如果存在最佳迭代次数,则保存该迭代次数;否则,保存所有迭代次数。如果 <= 0,则保存所有迭代次数。

  • start_iteration (int, optional (default=0)) – 应保存的迭代次数的起始索引。

  • importance_type (str, optional (default="split")) – 应保存的特征重要性类型。如果为 “split”,结果包含特征在模型中使用的次数。如果为 “gain”,结果包含使用该特征的分裂的总增益。

返回:

self – 返回自身。

返回类型:

CVBooster