机器学习实战(一)xgboost实战

机器学习实战(一)xgboost实战,第1张

目录

xgboost预测钢管混凝土柱极限承载力

1.1导入pandas及numpy和画图包

1.2导入数据

1.3划分训练集与测试集

1.4导入xgboost包

1.5导入误差分析模块

1.6进行交叉验证定义

1.7模型训练

1.8打印误差


xgboost预测钢管混凝土柱极限承载力 1.1导入pandas及numpy和画图包

导入数据包

# @Time : 2022/1/22 11:56
# @Author : hongzt
# @File : xgbt
import pandas as pd
import numpy as np
import warnings
warnings.filterwarnings("ignore")
from matplotlib import pyplot as plt
1.2导入数据

将数据转成csv后导入pycharm

train= pd.read_csv('E:\database\cfst\lincacfst.csv')
dem=train[["D (mm)","t (mm)","Le (mm)","fy (MPa)","fc (MPa)"]].values
object=train[["N Test (kN)"]].values
1.3划分训练集与测试集

基于skeran分类器划分测试集与训练集,按0.7与0.3划分

from sklearn.model_selection import train_test_split
x_train,x_test,y_trian,y_test=train_test_split(dem,object,test_size=0.3,shuffle=True)
1.4导入xgboost包

导入xgboost包,准备模型训练

import xgboost as xgbt
1.5导入误差分析模块
from sklearn.metrics import mean_squared_error
1.6进行交叉验证定义
from sklearn.model_selection import KFold
kf=KFold(n_splits=10)
rmse=[]
1.7模型训练
for train_indices,test_indices in kf.split(dem):
    X_train,X_test=dem[train_indices],dem[test_indices]
    Y_train, Y_test = object[train_indices], object[test_indices]
    xgbtRLR=xgbt.XGBRFRegressor()
    xgbtRLR.fit(X_train,Y_train)
    y_pred = xgbtRLR.predict(X_test)
    RSM=mean_squared_error(Y_test,y_pred)
    rmse.append(RSM)
1.8打印误差
print(rmse)
print(f'average rmse:{np.mean(rmse)}')

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/langs/569397.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-04-09
下一篇 2022-04-09

发表评论

登录后才能评论

评论列表(0条)

保存