全部版块 我的主页
论坛 数据科学与人工智能 数据分析与数据科学 R语言论坛
3389 0
2020-12-12
##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

二维码

扫码加我 拉你入群

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

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

相关推荐
栏目导航
热门文章
推荐文章

说点什么

分享

扫码加好友,拉您进群
各岗位、行业、专业交流群