import lightgbm as lgb
import pandas as pd
def lgb_train(x_train, y_train, x_test, y_test):
clf = lgb.LGBMClassifier(
boosting_type='gbdt',
# num_leaves=31,
num_leaves=31,
reg_alpha=0.05,
reg_lambda=1.5,
max_depth=-1,
n_estimators=1200,
objective='binary',
subsample=0.85,
colsample_bytree=0.8,
subsample_freq=1,
learning_rate=0.035,
# min_child_weight=0.1,
min_child_samples=25,
seed=2021,
nthread=-1)
clf.fit(X, y, eval_metric='auc', verbose=True, eval_set=[(x_train,y_train),(x_test,y_test)], early_stopping_rounds=5,categorical_feature='auto')
y_pred = clf.predict_proba(x_test)[:, 1]
auc = roc_auc_score(y_test, y_pred)
print(f"lgb-auc: {auc}")
importance = pd.Series(data=clf.feature_importances_, index=feature_col, name=("colname", "importance")).sort_values(
ascending=False).to_frame()
importance.to_csv('import.csv')
return clf