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
lightgbm 训练模型代码
最新推荐文章于 2025-05-27 18:00:51 发布
该博客介绍了如何使用LightGBM库训练一个二分类模型,详细配置了参数,包括boosting_type、num_leaves、learning_rate等,并在训练过程中应用了早停策略。最终通过ROC_AUC分数评估模型性能,并导出了特征重要性。
部署运行你感兴趣的模型镜像
您可能感兴趣的与本文相关的镜像
Yolo-v5
Yolo
YOLO(You Only Look Once)是一种流行的物体检测和图像分割模型,由华盛顿大学的Joseph Redmon 和Ali Farhadi 开发。 YOLO 于2015 年推出,因其高速和高精度而广受欢迎
633

被折叠的 条评论
为什么被折叠?



