楼主: 特种兵鲁
3471 0

[程序分享] 偏最小二乘法(PLSR)R语言简单的实现 [推广有奖]

  • 0关注
  • 0粉丝

初中生

61%

还不是VIP/贵宾

-

威望
0
论坛币
817 个
通用积分
0.2805
学术水平
0 点
热心指数
0 点
信用等级
0 点
经验
1500 点
帖子
1
精华
0
在线时间
34 小时
注册时间
2016-12-12
最后登录
2024-12-12

楼主
特种兵鲁 在职认证  发表于 2020-12-12 03:23:57 |AI写论文

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

求职就业群
赵安豆老师微信:zhaoandou666

经管之家联合CDA

送您一个全额奖学金名额~ !

感谢您参与论坛问题回答

经管之家送您两个论坛币!

+2 论坛币
##2020.02.03 by jingshan lu wrote
rm(list =ls() ) #clear all
classiftime1 <- proc.time()
library("openxlsx")
jianmo=read.xlsx("C:\\Users\\20162\\Desktop\\建模.xlsx")# this is calibration dataset, first column is dependent variable, other columns are independent variables
yanzheng=read.xlsx("C:\\Users\\20162\\Desktop\\验证.xlsx")#this isvalidation dataset
jianmoy=as.matrix(jianmo[,1])
jianmox=as.data.frame(jianmo[,-1])
yanzhengy=as.matrix(yanzheng[,1])
yanzhengx=as.data.frame(yanzheng[,-1])
##
library(pls)
library(plsVarSel)#VIP of this package can be used to calculate VIP of variables
## set the parameter unchanged
set.seed(1)
y.plsr=plsr(jianmoy~.,data=jianmox,scale=T,validation="CV")
component=which.min(y.plsr$validation$PRESS)
jianmopre=as.matrix(as.data.frame(y.plsr$validation$pred)[,component])
jianmoshice=jianmoy
#calculate VIP
y.plsr.vip=as.matrix(VIP(y.plsr,component))
#
jianmomoxing=cbind(jianmoshice,jianmopre)
plot(jianmoshice,jianmopre)
write.xlsx(jianmomoxing,file="C:\\Users\\20162\\Desktop\\建模模型.xlsx")#export calibration model that two columns data including measured and predicted dependent variable
write.xlsx(y.plsr.vip,file="C:\\Users\\20162\\Desktop\\模型VIP.xlsx")#export VIP of plsr model
## model validation
yanzhengyuce=as.matrix(as.data.frame(predict(y.plsr,yanzhengx))[,component])
yanzhengmoxing=cbind(yanzhengy,yanzhengyuce)
plot(yanzhengy,yanzhengyuce)
write.xlsx(yanzhengmoxing,file="C:\\Users\\20162\\Desktop\\验证模型.xlsx")#export validation model

# validationplot(y.plsr,val.type="RMSEP") show the RMSEP of the model
##

classiftime <-  proc.time() - classiftime1

二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

关键词:偏最小二乘法 最小二乘法 偏最小二乘 最小二乘 PLS R语言 PLSR

本帖被以下文库推荐

您需要登录后才可以回帖 登录 | 我要注册

本版微信群
加好友,备注cda
拉您进交流群
GMT+8, 2026-1-6 18:02