[R] predict kernelmatrix

Nelson Hernandez Gonzalez nhernandezgo at unal.edu.co
Tue Aug 14 00:40:11 CEST 2007


HI

I got a problem in the predict function of the kernlab.

I want to use ksvm and predict with  kernelmatrix (S4 method for signature 'kernelMatrix')

#executing the following sentences 

library(kernlab)
# identity kernel

k <- function(x,y) {
 n<-length(x)
 cont<-0
  for(i in 1:n){
   
    if(x[i]==y[i]){
      cont<-cont+1
    }
  }
cont
}
class(k) <- "kernel"

data(promotergene) 
ind <- sample(1:dim(promotergene)[1],20) 
genetrain <- promotergene[-ind, -1]
genetest <- promotergene[ind,-1 ]

kx <- kernelMatrix(k, as.matrix(genetrain))
#y<-as.vector(promotergene[-ind,1 ])
y<-as.factor(promotergene[-ind,1 ])
y
gene1 <- ksvm(kx, y, type="C-svc")
gene1
genetype <- predict(gene1,genetest)
Error en as.matrix(Z) : objeto "Z" no encontrado

#genetest1<-as.matrix(genetest)
#genetype <- predict(gene1,genetest1)
genetype

thank you,
nelsonhernandez
nhernandezgo en unal.edu.co



More information about the R-help mailing list