|
@@ -130,14 +130,15 @@ class LightGBM(object):
|
|
|
)
|
|
|
test_data = lgb.Dataset(X_test, label=Y_test, reference=train_data)
|
|
|
params = {
|
|
|
- 'num_leaves': 25,
|
|
|
- 'learning_rate': 0.00435469653451866,
|
|
|
- 'feature_fraction': 0.8659696885542688,
|
|
|
- 'bagging_fraction': 0.4671847911224712,
|
|
|
+ 'num_leaves': 20,
|
|
|
+ 'learning_rate': 0.03372815687364156,
|
|
|
+ 'feature_fraction': 0.48848665517495693,
|
|
|
+ 'bagging_fraction': 0.679118348482125,
|
|
|
'bagging_freq': 1,
|
|
|
- # 'min_child_samples': 65,
|
|
|
- "num_threads": 16, # 线程数量
|
|
|
+ "num_threads": 16,
|
|
|
+ 'min_child_samples': 38
|
|
|
}
|
|
|
+
|
|
|
# 训练模型
|
|
|
num_round = 100
|
|
|
print("开始训练......")
|
|
@@ -204,20 +205,20 @@ class LightGBM(object):
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
- # i = int(input("输入 1 训练, 输入 2 预测:\n"))
|
|
|
- # if i == 1:
|
|
|
- # f = "train"
|
|
|
- # dt = "whole"
|
|
|
- # L = LightGBM(flag=f, dt=dt)
|
|
|
- # L.train_model()
|
|
|
- # elif i == 2:
|
|
|
- # f = "predict"
|
|
|
- # dt = int(input("输入日期, 16-21:\n"))
|
|
|
- # L = LightGBM(flag=f, dt=dt)
|
|
|
- # # L.evaluate_model()
|
|
|
- # L.feature_importance()
|
|
|
- L = LightGBM("train", "whole")
|
|
|
- study = optuna.create_study(direction='maximize')
|
|
|
- study.optimize(L.bays_params, n_trials=100)
|
|
|
- print('Number of finished trials:', len(study.trials))
|
|
|
- print('Best trial:', study.best_trial.params)
|
|
|
+ i = int(input("输入 1 训练, 输入 2 预测:\n"))
|
|
|
+ if i == 1:
|
|
|
+ f = "train"
|
|
|
+ dt = "whole"
|
|
|
+ L = LightGBM(flag=f, dt=dt)
|
|
|
+ L.train_model()
|
|
|
+ elif i == 2:
|
|
|
+ f = "predict"
|
|
|
+ dt = int(input("输入日期, 16-21:\n"))
|
|
|
+ L = LightGBM(flag=f, dt=dt)
|
|
|
+ L.evaluate_model()
|
|
|
+ L.feature_importance()
|
|
|
+ # L = LightGBM("train", "whole")
|
|
|
+ # study = optuna.create_study(direction='maximize')
|
|
|
+ # study.optimize(L.bays_params, n_trials=100)
|
|
|
+ # print('Number of finished trials:', len(study.trials))
|
|
|
+ # print('Best trial:', study.best_trial.params)
|