XGBoost梯度提升方法实验

XGBoost梯度提升方法

实验环境为google colab

XGBoost参数

这里可以参考博客如下:

作者:大石头的笔记
链接:https://juejin.cn/post/6844904134336839693
来源:掘金

XGBoost的参数可以分为三种类型:通用参数、booster参数以及学习目标参数

  • General parameters:参数控制在提升(boosting)过程中使用哪种booster,常用的booster有树模型(tree)和线性模型(linear model)。
  • Booster parameters:这取决于使用哪种booster。
  • Learning Task parameters:控制学习的场景,例如在回归问题中会使用不同的参数控制排序。
  • 除了以上参数还可能有其它参数,在命令行中使用
import pandas as pd
import numpy as np

df = pd.read_csv('/content/drive/MyDrive/NOx/dataset/NOx_df.csv')
df
Unnamed: 0tmainsteamfuelo2primaryfanfanAcoalBcoalCcoalDcoalbrunoutNOx1NOx2
000.0000000.0396180.1621460.6552390.1320230.0612730.6587950.4187020.4409410.0000620.10.4351720.405764
110.0000010.0396140.1621720.6539350.1295840.0605100.6543080.4151850.4402870.0000620.10.4351720.405764
220.0000020.0396100.1621990.6526310.1271460.0597480.6498220.4116670.4396330.0000620.10.4351720.405764
330.0000030.0396060.1622260.6513280.1346340.0589850.6453360.4117900.4400690.0000620.10.4351720.405764
440.0000050.0396020.1622520.6500240.1421220.0582220.6408500.4119130.4405050.0000620.10.4351720.405764
.............................................
8639958639950.9999950.3424070.3364400.5235090.1683940.0852920.2851600.3968350.4216430.3695581.00.5293680.587031
8639968639960.9999970.3432970.3372150.5227510.1583690.0839100.2724710.3966280.4211260.3687941.00.5295740.588070
8639978639970.9999980.3441880.3379890.5219940.1483440.0825270.2597810.3964200.4206090.3680301.00.5304180.588785
8639988639980.9999990.3450790.3387630.5212360.1310150.0841450.2689460.3953240.4224630.3684121.00.5312620.589500
8639998639991.0000000.3459690.3395380.5204780.1136850.0857630.2781110.3942290.4243170.3687941.00.5321050.590214

864000 rows × 14 columns

读取数据

X = df[["t",'mainsteam','fuel','o2','primaryfan','fan','Acoal','Bcoal','Ccoal','Dcoal','brunout']].values
y = df[['NOx1']].values

X.shape, y.shape
((864000, 11), (864000, 1))

切分训练集和测试集

from sklearn.model_selection import train_test_split

# 划分数据集,70% 训练数据和 30% 测试数据
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.3)

X_train.shape, X_test.shape, y_train.shape, y_test.shape
((604800, 11), (259200, 11), (604800, 1), (259200, 1))

XGBoost梯度提升回归方法

import xgboost as xgb

model_r = xgb.XGBRegressor()
model_r
XGBRegressor(base_score=0.5, booster='gbtree', colsample_bylevel=1,
             colsample_bynode=1, colsample_bytree=1, gamma=0,
             importance_type='gain', learning_rate=0.1, max_delta_step=0,
             max_depth=3, min_child_weight=1, missing=None, n_estimators=100,
             n_jobs=1, nthread=None, objective='reg:linear', random_state=0,
             reg_alpha=0, reg_lambda=1, scale_pos_weight=1, seed=None,
             silent=None, subsample=1, verbosity=1)
model_r.fit(X_train, y_train)  # 使用训练数据训练
model_r.score(X_test, y_test)  # 使用测试数据计算准确度

模型测试准确率为80.71%

给出预测结果

y_ = model_r.predict(X_test)
y_, y_test
import matplotlib.pyplot as plt
from matplotlib.pylab import rcParams
%matplotlib inline

epochs = range(0, y_test.shape[0])
plt.figure(figsize=(10, 6))
plt.scatter(epochs, y_test)

png

plt.figure(figsize=(10, 6))
plt.scatter(epochs, y_)

png

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

小凡爱学习

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值