xgboost使用小结

发布时间 2023-09-26 15:28:00作者: ohmygirl

一、参考文献:

1. https://www.jianshu.com/p/9de0f73efc4c   使用Xgboost进行回归

2. https://zhuanlan.zhihu.com/p/374399558/ 线性回归模型总结

3. https://zhuanlan.zhihu.com/p/562983875   xgboost详解

4. https://zhuanlan.zhihu.com/p/389399280 深度学习-回归问题

5. https://mp.weixin.qq.com/s?__biz=MzA4ODcwOTExMQ==&mid=2655687562&idx=6&sn=704589449b438474928a6d5736c2dc91 7大经典回归问题

6. https://zhuanlan.zhihu.com/p/546048176?utm_id=0 xgboost常见特征归一化

二、xgboost回归demo

1. 加载样本

data = pd.read_csv("data/tt.csv", header=[0])
data_train = data[0:int(len(data) * 9 / 10)]
data_test = data[int(len(data) * 9 / 10):len(data)]

train_x = np.array(data_train.iloc[:, [i for i in range(data_train.shape[1]-1)]])
train_y = np.array(data_train['col_67'])

test_x = np.array(data_test.iloc[:, [i for i in range(data_test.shape[1]-1)]])
test_y = np.array(data_test['col_67'])

2. 模型参数

xgb_model = xgb.XGBRegressor(
    max_depth=6,
    learning_rate=0.05,
    n_estimators=150,
    objective='reg:squarederror',
    booster='gbtree',
    random_state=0
)

3. 模型拟合/训练

reg_model = xgb_model.fit(train_x, train_y)

4. 模型预测

x_predicted = xgb_model.predict(test_x)
print(x_predicted)