I'm trying to predict some data from PCA using leave-one-out (LOO) cross validation.
The prcomp
goes well, however when I come to predict
the function gets upset
error: 'newdata' must be a matrix or data frame
because I'm supplying a vector (ie a single row) and not a matrix (ie multiple rows).
I've tried as.data.frame
and as.matrix
and various varieties thereof but I still get errors
error: 'newdata' does not have named columns matching one or more of the original columns`
In my example here loo
is the LOO index and mydata
and myinfo
contain the data and metadata respectively.
tdata = mydata[-loo,]
tinfo = myinfo[-loo,]
vdata = mydata[loo,]
vinfo = myinfo[loo,]
p = prcomp( tdata )
predict(p, newdata = vdata )
没关系,找到了它:
predict(p, newdata = as.data.frame(t(vdata)) )
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.