[libsvm] predict function error
0
0
Entering edit mode
Zhe Liu ▴ 90
@zhe-liu-4199
Last seen 10.2 years ago
Dear Bioconductor users, There is a error message when I run the following code. It is used to load microarray data and use the top 1000 genes for training svm to classify test set . > library(e1071) Loading required package: class > f=read.table("F:\\lab\\microarray analysis\\VEH LPS\\exprs.txt", sep="\t",header=FALSE,col.names=c("Gene","VEH","VEH","VEH","VEH","VEH" ,"LPS","LPS","LPS","LPS","LPS")) > tf=t(f) > colnames(tf)=tf[1,] > tf=tf[-1,] > tf=as.data.frame(tf) > array <- apply(tf[,2:24928],c(1,2),as.numeric) > label <- as.factor(tf$ENTREZGENE) > > n <- nrow(array) #get sample number > permutation <- sample(1:n) > array.perm <- array[permutation,] # random permutation of samples > label.perm <- label[permutation] # same permutation of labels > > k <- 5 #set cross validation steps > > for (i in 1:k){ + win <- round(n/k) # size of window + cv <- ((i-1)*win+1):min(n,i*win) # move window + + CV.label.test <- label.perm[cv] + CV.label.train <- label.perm[-cv] + + CV.train.neg.num <- nrow(as.data.frame(CV.label.train[CV.label.train=="VEH"])) + CV.train.pos.num <- nrow(as.data.frame(CV.label.train[CV.label.train=="LPS"])) + CV.train.num <- CV.train.pos.num+CV.train.neg.num + + CV.test <- array.perm[cv,] # samples within window + CV.train <- array.perm[-cv,] # samples outside window + + CV.train.pos <- as.data.frame(CV.train)[as.data.frame(CV.label.train)=="LPS",] # matrix of positive samples + CV.train.pos.mean <- apply(CV.train.pos,2,mean) # compute mean of each column (gene) + CV.train.pos.var <- apply(CV.train.pos,2,var) # compute variance of each column (gene) + + CV.train.neg <- as.data.frame(CV.train)[as.data.frame(CV.label.train)=="VEH",] # matrix of positive samples + CV.train.neg.mean <- apply(CV.train.neg,2,mean) # compute mean of each column (gene) + CV.train.neg.var <- apply(CV.train.neg,2,var) + + tscore <-(abs(CV.train.pos.mean-CV.train.neg.mean)/sqrt((CV.train.pos.num-1)* CV.train.pos.var+(CV.train.neg.num-1)*CV.train.neg.var))*sqrt(CV.train .pos.num*CV.train.neg.num*(CV.train.num-2)/CV.train.num) + index <- order(tscore, decreasing=TRUE) + CV.train=CV.train[,index[1:100]] + + svm.train<-svm(CV.train, CV.label.train, type="C-classification", kernel="linear", cross=5, scale=TRUE) + } > pred<-predict(svm.train,CV.test) Error in scale.default(newdata[, object$scaled, drop = FALSE], center = object$x.scale$"scaled:center", : length of 'center' must equal the number of columns of 'x' I wonder what is the reason for such kind of error. > sessionInfo() R version 2.11.1 (2010-05-31) i386-pc-mingw32 locale: [1] LC_COLLATE=Chinese_People's Republic of China.936 [2] LC_CTYPE=Chinese_People's Republic of China.936 [3] LC_MONETARY=Chinese_People's Republic of China.936 [4] LC_NUMERIC=C [5] LC_TIME=Chinese_People's Republic of China.936 attached base packages: [1] stats graphics grDevices utils datasets methods base other attached packages: [1] e1071_1.5-24 class_7.3-2 Thanks a lot! -- Best Regards, Zhe Liu [[alternative HTML version deleted]]
• 1.6k views
ADD COMMENT

Login before adding your answer.

Traffic: 998 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6