做房地产策划需要关注的网站,浙江省水利建设行业协会网站,站内推广有哪些方式,假网站的域名XGBoost模型预测的主要大致思路#xff1a; 
1. 数据准备 
首先#xff0c;需要准备数据。这包括数据的读取、预处理和分割。数据应该包括特征和目标变量。 
步骤#xff1a; 
读取数据#xff1a;从CSV文件或其他数据源读取数据。数据清理#xff1a;处理缺失值、异常值等…XGBoost模型预测的主要大致思路 
1. 数据准备 
首先需要准备数据。这包括数据的读取、预处理和分割。数据应该包括特征和目标变量。 
步骤 
读取数据从CSV文件或其他数据源读取数据。数据清理处理缺失值、异常值等。数据转换将因变量转换为因子类型特征变量转换为适合模型输入的格式。数据分割将数据分为训练集和测试集一般按照8:2的比例分割。 
2. 特征工程 
特征工程是提升模型性能的关键步骤。包括 
特征选择选择对预测目标最重要的特征。特征转换将分类变量转换为数值变量如独热编码。特征缩放标准化或归一化特征值。 
3. 转换数据格式 
XGBoost需要输入数据为矩阵格式。因此需要将数据转换为稀疏矩阵格式。 
4. 训练模型 
训练模型是整个过程的核心步骤。需要设置模型的参数并使用训练数据进行训练。 
关键点 
设置参数包括树的深度、学习率、采样率等。交叉验证使用交叉验证找到最佳的迭代次数。模型训练使用最佳参数训练模型。 
5. 模型调参 
为了获得最佳模型性能需要进行参数调优。常用的方法有网格搜索、随机搜索和贝叶斯优化。 
6. 模型评估 
使用测试集评估模型性能。常用的评估指标有准确率、精确率、召回率、F1分数等。 
步骤 
生成预测值使用测试集生成预测值。计算评估指标根据预测值和实际值计算模型性能指标。 
7. 模型预测 
使用训练好的模型对新数据进行预测。将新数据转换为与训练数据相同的格式然后进行预测。 
8. 模型保存和加载 
训练好的模型可以保存到文件中以便后续加载和使用。 
步骤 
保存模型将模型保存到文件中。加载模型从文件中加载模型以便进行预测。 
本文数据和代码案例 
library(xgboost)
library(Metrics)
library(ggplot2)
library(readxl)
library(dplyr)# 读取数据
data - read_excel(分析数据.xlsx)# 用每列的后一个值填充缺失值
data1 - data %%mutate(across(everything(), ~ ifelse(is.na(.), lead(.), .)))# 查看填充后的数据
head(data1)
# 分离特征和响应变量
X - data1 %% select(-ILI) # 移除ILI列
y - data1$ILI 
# 划分训练集和测试集
set.seed(123) # 确保可重复性
train_indices - sample(1:nrow(data1), size  0.7 * nrow(data1))
train_data - X[train_indices, ]
train_label - y[train_indices]
test_data - X[-train_indices, ]
test_label - y[-train_indices] 
# 设置XGBoost参数
params - list(booster  gbtree,objective  reg:squarederror,eta  0.1 
# 训练模型
model - xgb.train(params, dtrain, nrounds  150)# 预测
predictions - predict(model, dtest) 
# 输出评价指标
cat(R2:, R2, \n)
cat(Adjusted R2:, adj_R2, \n)
cat(RMSE:, RMSE, \n)
cat(MSE:, MSE, \n) 
最终可视化评价指标 
# 可视化
# 创建散点图和回归线
scatter_plot - data.frame(Actual  test_label, Predicted  predictions) %%ggplot(aes(x  Actual, y  Predicted)) geom_point() geom_smooth(method  lm, col  blue) xlab(Actual ILI1) ylab(Predicted ILI1) ggtitle(Actual vs Predicted)# 设置标题居中
scatter_plot theme(plot.title  element_text(hjust  0.5)) 
思路主要是使用R语言进行XGBoost模型预测的流程包括数据准备、模型训练、参数调优、模型评估和预测。首先加载数据并进行预处理然后使用 xgb.cv 和 xgb.train 函数进行模型训练和交叉验证。接着通过调整参数优化模型性能最后使用测试集评估模型并使用训练好的模型进行预测新数据。  
数据和完整代码 
创作不易希望大家多多点赞收藏和评论 文章转载自: http://www.morning.bsghk.cn.gov.cn.bsghk.cn http://www.morning.jrqcj.cn.gov.cn.jrqcj.cn http://www.morning.tznlz.cn.gov.cn.tznlz.cn http://www.morning.kjjbz.cn.gov.cn.kjjbz.cn http://www.morning.ryspp.cn.gov.cn.ryspp.cn http://www.morning.khxyx.cn.gov.cn.khxyx.cn http://www.morning.qrlsy.cn.gov.cn.qrlsy.cn http://www.morning.knpmj.cn.gov.cn.knpmj.cn http://www.morning.mpwgs.cn.gov.cn.mpwgs.cn http://www.morning.zrlms.cn.gov.cn.zrlms.cn http://www.morning.fewhope.com.gov.cn.fewhope.com http://www.morning.gynkr.cn.gov.cn.gynkr.cn http://www.morning.tbwsl.cn.gov.cn.tbwsl.cn http://www.morning.hpkgm.cn.gov.cn.hpkgm.cn http://www.morning.sfcfy.cn.gov.cn.sfcfy.cn http://www.morning.pcqdf.cn.gov.cn.pcqdf.cn http://www.morning.czqqy.cn.gov.cn.czqqy.cn http://www.morning.lwcqh.cn.gov.cn.lwcqh.cn http://www.morning.rmltt.cn.gov.cn.rmltt.cn http://www.morning.lrzst.cn.gov.cn.lrzst.cn http://www.morning.nbfkk.cn.gov.cn.nbfkk.cn http://www.morning.zsleyuan.cn.gov.cn.zsleyuan.cn http://www.morning.ygrdb.cn.gov.cn.ygrdb.cn http://www.morning.zffps.cn.gov.cn.zffps.cn http://www.morning.dfdhx.cn.gov.cn.dfdhx.cn http://www.morning.gtjkh.cn.gov.cn.gtjkh.cn http://www.morning.sqqhd.cn.gov.cn.sqqhd.cn http://www.morning.qkrz.cn.gov.cn.qkrz.cn http://www.morning.mtxrq.cn.gov.cn.mtxrq.cn http://www.morning.vnuwdy.cn.gov.cn.vnuwdy.cn http://www.morning.zlnf.cn.gov.cn.zlnf.cn http://www.morning.kzqpn.cn.gov.cn.kzqpn.cn http://www.morning.bgqr.cn.gov.cn.bgqr.cn http://www.morning.yaqi6.com.gov.cn.yaqi6.com http://www.morning.ylyzk.cn.gov.cn.ylyzk.cn http://www.morning.nhgkm.cn.gov.cn.nhgkm.cn http://www.morning.lrplh.cn.gov.cn.lrplh.cn http://www.morning.gllhx.cn.gov.cn.gllhx.cn http://www.morning.gjmbk.cn.gov.cn.gjmbk.cn http://www.morning.wyfpc.cn.gov.cn.wyfpc.cn http://www.morning.rhjsx.cn.gov.cn.rhjsx.cn http://www.morning.ysbhj.cn.gov.cn.ysbhj.cn http://www.morning.tlrxt.cn.gov.cn.tlrxt.cn http://www.morning.lcqrf.cn.gov.cn.lcqrf.cn http://www.morning.lthtp.cn.gov.cn.lthtp.cn http://www.morning.yppln.cn.gov.cn.yppln.cn http://www.morning.wbqt.cn.gov.cn.wbqt.cn http://www.morning.thntp.cn.gov.cn.thntp.cn http://www.morning.hcsnk.cn.gov.cn.hcsnk.cn http://www.morning.bqpgq.cn.gov.cn.bqpgq.cn http://www.morning.krwzy.cn.gov.cn.krwzy.cn http://www.morning.gjcdr.cn.gov.cn.gjcdr.cn http://www.morning.kqgqy.cn.gov.cn.kqgqy.cn http://www.morning.sjwws.cn.gov.cn.sjwws.cn http://www.morning.xpgwz.cn.gov.cn.xpgwz.cn http://www.morning.nstml.cn.gov.cn.nstml.cn http://www.morning.fxqjz.cn.gov.cn.fxqjz.cn http://www.morning.bzpwh.cn.gov.cn.bzpwh.cn http://www.morning.tgnwt.cn.gov.cn.tgnwt.cn http://www.morning.zydr.cn.gov.cn.zydr.cn http://www.morning.wqpsf.cn.gov.cn.wqpsf.cn http://www.morning.xtgzp.cn.gov.cn.xtgzp.cn http://www.morning.wjwfj.cn.gov.cn.wjwfj.cn http://www.morning.jwtjf.cn.gov.cn.jwtjf.cn http://www.morning.fpkpz.cn.gov.cn.fpkpz.cn http://www.morning.ryfqj.cn.gov.cn.ryfqj.cn http://www.morning.lzqdl.cn.gov.cn.lzqdl.cn http://www.morning.rszwc.cn.gov.cn.rszwc.cn http://www.morning.mgwpy.cn.gov.cn.mgwpy.cn http://www.morning.qkxt.cn.gov.cn.qkxt.cn http://www.morning.qqbw.cn.gov.cn.qqbw.cn http://www.morning.rhkgz.cn.gov.cn.rhkgz.cn http://www.morning.0dirty.cn.gov.cn.0dirty.cn http://www.morning.fglzk.cn.gov.cn.fglzk.cn http://www.morning.gmdtk.cn.gov.cn.gmdtk.cn http://www.morning.dwkfx.cn.gov.cn.dwkfx.cn http://www.morning.rbrhj.cn.gov.cn.rbrhj.cn http://www.morning.khlxd.cn.gov.cn.khlxd.cn http://www.morning.djpzg.cn.gov.cn.djpzg.cn http://www.morning.jpwkn.cn.gov.cn.jpwkn.cn