在进行预测的时候,y_pred_1 = gbm.predict(X_val, num_iteration=gbm.best_iteration)
lightgbm报上述错误。
查阅官方文档后,明白与参数early_stopping_rounds
- early_stopping_rounds (int or None, optional (default=None)) – Activates early stopping. The model will train until the validation score stops improving. Requires at least one validation data and one metric. If there’s more than one, will check all of them. If early stopping occurs, the model will add best_iteration field.
early_stopping_rounds(int或None,可选(default = None)) - 激活提前停止。 该模型将训练,直到验证分数停止改进。 至少需要一个验证数据和一个指标。 如果有多个,将检查所有这些。 如果提前停止,模型将添加best_iteration字段。
最后一句的意思是如果模型提前停止,模型才会添加best_iteration。如果没有提前停止,就不会有这个参数。不知道我的理解对不对。。。
要是不对,欢迎指正!
本文探讨了在使用LightGBM模型时遇到的关于best_iteration参数的问题。特别是当模型训练过程中启用了提前停止机制时,best_iteration字段的含义及其在预测阶段的应用。
1万+





