early_stopping_rounds= 200,
                        verbose_eval=100,
                        seed=47

                         )
        print("交叉验证AUC:{},参数:{}".format(max(clf['auc-mean']), params))
        gc.collect()
        return max(clf['auc-mean'])





train_df = under_sample.under_sample_train_data()
test_df = pd.read_csv('/home/mengyuan/huawei/data/test_data_A.csv',sep='|')
train_df,test_df=feature_process.generate_features(train_df,test_df)

feats = [f for f in train_df.columns if f not in FEATS_EXCLUDED]

study = optuna.create_study(direction="maximize")
study.optimize(objective, n_trials=100)

print('Number of finished trials: {}'.format(len(study.trials)))

print('Best trial:')
trial = study.best_trial

print('  Value: {}'.format(trial.value))

print('  Params: ')
for key, value in trial.params.items():
# * 2 lightgbm
# * 1 xgboost
# * 1 catboost
# * 1 dense neural network
#
# **Layer 2**:
# * Lasso regression
# * Ridge regression
#


train = under_sample.under_sample_train_data()

test = pd.read_csv('/home/mengyuan/huawei/data/test_data_B.csv',sep='|')

train,test=feature_process.generate_features(train,test)

# ######存储结果节点(代替上面数据载入)###################################################################################
# with open('/data/mengyuan/huawei/ensemble/{}.pkl'.format('train'), 'wb') as file:
#     pickle.dump(train, file)
# with open('/data/mengyuan/huawei/ensemble/{}.pkl'.format('test'), 'wb') as file:
#     pickle.dump(test, file)
# print('成功存储train、test的pickle。。。。')
######################################################################################################
####读取节点##############
with open('/data/mengyuan/huawei/ensemble/{}.pkl'.format('train'), 'rb') as file:
    train=pickle.load(file)
with open('/data/mengyuan/huawei/ensemble/{}.pkl'.format('test'), 'rb') as file:
    test=pickle.load(file)
print('成功读入train、test的pickle。。。。')
#####################################################################################################