分类因子的偏最小二乘回归

时间:2014-07-11 11:18:42

标签: r partial least-squares

我使用R中的pls包调整一个分类因子(2个级别 - 是或不是)的偏最小二乘回归。我尝试在预测值中使用round()函数来做出决定,如果结果是我的因素中的第一级或第二级,这种方法听起来是否正确?

require(pls) 

人工数据

T<-as.factor(sort(rep(c("be", "nottobe"), 100))) 

y1 <- c(rnorm(100,1,0.1),rnorm(100,1,0.1)) 

y2 <- c(rnorm(100,10,0.3),rnorm(100,10,0.6)) 
y3 <- c(rnorm(100,10,2.3),rnorm(100,11,2.6)) 
y4 <- c(rnorm(100,5,0.5),rnorm(100,7,0.5)) 
y5 <- c(rnorm(100,0,0.1),rnorm(100,0,0.1)) 

创建数据框

avaliacao <- as.numeric(T) 
espectro <- cbind(y1,y2,y3,y4,y5) 
dados <- data.frame(avaliacao = I(as.matrix(avaliacao)), bands = I(as.matrix(espectro))) 

PLS回归

taumato <- plsr(avaliacao ~ bands, ncomp = 5, validation = "LOO", data=dados) 
summary(taumato) 

组件分析

plot(taumato, plottype = "scores", comps = 1:5) 

交叉验证

taumato.cv <- crossval(taumato, segments = 10) 
plot(MSEP(taumato.cv), legendpos = "topright") 
summary(taumato.cv, what = "validation") 
plot(taumato, xlab ="medição", ylab="predição", ncomp = 3, asp = 1, main=" ", line = TRUE) 

3个组件的预测

T<-as.factor(sort(rep(c("be", "nottobe"), 50))) 

y1 <- c(rnorm(100,1,0.1),rnorm(100,1,0.1)) 
y2 <- c(rnorm(100,10,0.3),rnorm(100,10,0.6)) 
y3 <- c(rnorm(100,10,2.3),rnorm(100,11,2.6)) 
y4 <- c(rnorm(100,5,0.5),rnorm(100,7,0.5)) 
y5 <- c(rnorm(100,0,0.1),rnorm(100,0,0.1)) 

espectro2 <- cbind(y1,y2,y3,y4,y5) 
new.dados <- data.frame(bands = I(as.matrix(espectro2))) 
round(predict(taumato, ncomp = 3, newdata = new.dados))##

0 个答案:

没有答案