机器学习笔记 - AutoML框架LightGBM初体验

一、LightGBM框架概述

        GBDT (Gradient Boosting Decision Tree) 是机器学习中一个长盛不衰的模型,其主要思想是利用弱分类器(决策树)迭代训练以得到最优模型,该模型具有训练效果好、不易过拟合等优点。GBDT不仅在工业界应用广泛,通常被用于多分类、点击率预测、搜索排序等任务;在各种数据挖掘竞赛中也是致命武器,据统计Kaggle上的比赛有一半以上的冠军方案都是基于GBDT。

        LightGBM(Light Gradient Boosting Machine)是一个实现GBDT算法的框架,它使用基于树的学习算法。具有以下优点:

        1、更快的训练速度和更高的效率。

        2、降低内存使用率。

        3、更好的准确性。

        4、支持并行、分布式和 GPU 学习。

        5、能够处理大规模数据。

        在公共数据集上的比较实验表明,LightGBM 在效率和准确性上都优于现有的 boosting 框架,并且显着降低了内存消耗。更重要的是,分布式学习实验表明,LightGBM 可以通过使用多台机器在特定设置下进行训练来实现线性加速。

        使用文档地址

Welcome to LightGBM’s documentation! — LightGBM 3.3.2.99 documentationhttps://lightgbm.readthedocs.io/en/latest/        github地址

GitHub - microsoft/LightGBM: A fast, distributed, high performance gradient boosting (GBT, GBDT, GBRT, GBM or MART) framework based on decision tree algorithms, used for ranking, classification and many other machine learning tasks.A fast, distributed, high performance gradient boosting (GBT, GBDT, GBRT, GBM or MART) framework based on decision tree algorithms, used for ranking, classification and many other machine learning tasks. - GitHub - microsoft/LightGBM: A fast, distributed, high performance gradient boosting (GBT, GBDT, GBRT, GBM or MART) framework based on decision tree algorithms, used for ranking, classification and many other machine learning tasks.https://github.com/Microsoft/LightGBM        快速安装

pip install lightgbm

        相关论文

https://proceedings.neurips.cc/paper/2017/file/6449f44a102fde848669bdd9eb6b76fa-Paper.pdficon-default.png?t=M276https://proceedings.neurips.cc/paper/2017/file/6449f44a102fde848669bdd9eb6b76fa-Paper.pdf

二、简单示例

        示例是基于Kaggle表格游乐场2022Feb的比赛。关于比赛情况可以参考。

机器学习笔记 - Kaggle表格游乐场 Feb 2022 学习一_bashendixie5的博客-CSDN博客一、比赛介绍Kaggle的表格游乐场从2021年开始,每个月1号都会有新的比赛,奖品应该是什么小礼品,官方的意思是给为初学者举办的比赛,不过在这里能看到高手们的思考问题的思路以及处理的办法,确实是收益良多。Tabular Playground Series - Feb 2022 | Kagglehttps://www.kaggle.com/c/tabular-playground-series-feb-2022/overview1、Tabular Playground Serie...https://blog.csdn.net/bashendixie5/article/details/123034023        训练代码

import lightgbm as lgb
import pandas as pd
import pickle

print("LGB test")
clf = lgb.LGBMClassifier(
        boosting_type='gbdt', num_leaves=55, reg_alpha=0.0, reg_lambda=1,
        max_depth=15, n_estimators=6000, objective='binary',
        subsample=0.8, colsample_bytree=0.8, subsample_freq=1,
        learning_rate=0.06, min_child_weight=1, random_state=20, n_jobs=-1
    )

X = pd.read_csv('data/train_data.csv')
label = pd.read_csv('data/train_label.csv')
y = label.target

clf.fit(X, y, callbacks=[lgb.log_evaluation(period=1, show_stdv=True)])
#pre=clf.predict(testdata)

# 保存模型
s=pickle.dumps(clf)
f=open('lightgbm_v2.model', "wb+")
f.write(s)
f.close()

        测试代码

print("这是lightgbm")
f2 = open('lightgbm_v2.model', 'rb')
s2 = f2.read()
model1 = pickle.loads(s2)
test_X = pd.read_csv('data/test.csv')

predictions = model1.predict(test_X)
preds = []
for pred in predictions:
    preds.append(week_day_dict[pred])

res = pd.DataFrame()
res['target'] = preds
res.to_csv("predict_lightgbm_v2.csv")

        数据没有经过处理,训练后提交到kaggle,得分0.95169,得分情况只能说是差强人意,需要在调整。

猜你喜欢

转载自blog.csdn.net/bashendixie5/article/details/123554288
今日推荐