LightGBM 可以使用一个 pairs 的 list 或一个字典来设置参数:

 1.Booster提升器的参数:

param={'num_class':33, 'boosting_type':'gbdt', 'max_depth':3, 'metric': {'multi_logloss'}, 'learning_rate':0.01}

 2.可以制定多eval指标:

1 param['metric'] = ['auc', 'binary_logloss']

 

  模型的训练:需要一个params参数和训练数据集

1 num_round = 10
2 bst = lgb.train(param, train_data, num_round, valid_sets=[test_data])

  训练完成后存储模型:

1 bst.save_model('model.txt')

  模型使用如下方式来加载:

1 bst = lgb.Booster(model_file='model.txt')  #init model

 

  预测:已将训练或者加载好的模型都可以对数据集进行预测

1 gbm.predict(pre_x.values, num_iteration=gbm.best_iteration)

  在训练过程中使用了提前停止,使用best_iteration从最佳迭代中获取训练结果

param['metric'] = ['auc', 'binary_logloss']

相关文章:

  • 2022-12-23
  • 2021-10-14
  • 2021-08-24
  • 2021-11-04
  • 2021-07-31
  • 2021-10-29
  • 2022-01-04
  • 2021-10-06
猜你喜欢
  • 2022-12-23
  • 2021-05-15
  • 2021-09-11
  • 2022-02-03
  • 2022-12-23
  • 2021-09-30
相关资源
相似解决方案