[R] kernlab kpca predict

Jessica Streicher j.streicher at micromata.de
Tue Jul 31 16:50:08 CEST 2012


Hm.. seems like its a problem with loading it in the profile..

If i load it again in the console it works fine. Must have something to do with the masking.

----------

Changed load-order with the package which required "stats" that did the masking, and it works now, so, nevermind.

On 31.07.2012, at 16:25, Jessica Streicher wrote:

> Hi!
> 
> The kernlab function kpca() mentions that new observations can be transformed by using predict. Theres also an example in the documentation, but as you can see i am getting an error there (As i do with my own data). I'm not sure whats wrong at the moment. I haven't any predict functions written by myself in the workspace either. I've tested it with using the matrix version and the dataframe/formula version on kpca.
> 
> data(iris)
> test <- sample(1:150,20)
> kpc <- kpca(~.,data=iris[-test,-5],kernel="rbfdot",kpar=list(sigma=0.2),features=2)
> emb <- predict(kpc,iris[test,-5])
> Error in UseMethod("predict") : 
>  no applicable method for 'predict' applied to an object of class "c('kpca', 'prc')"
> 
> str(kpc)
> Formal class 'kpca' [package "kernlab"] with 9 slots
>  ..@ rotated : num [1:130, 1:2] -9.43 -9.17 -9.09 -9.43 -8.53 ...
>  .. ..- attr(*, "dimnames")=List of 2
>  .. .. ..$ : chr [1:130] "1" "2" "4" "5" ...
>  .. .. ..$ : NULL
>  ..@ pcv     : num [1:130, 1:2] -0.224 -0.218 -0.216 -0.225 -0.203 ...
>  ..@ eig     : Named num [1:2] 0.323 0.119
>  .. ..- attr(*, "names")= chr [1:2] "Comp.1" "Comp.2"
>  ..@ kernelf :Formal class 'rbfkernel' [package "kernlab"] with 2 slots
>  .. .. ..@ .Data:function (x, y = NULL)  
>  .. .. ..@ kpar :List of 1
>  .. .. .. ..$ sigma: num 0.2
>  ..@ kpar    : list()
>  ..@ xmatrix : num [1:130, 1:4] 5.1 4.9 4.6 5 5.4 4.6 5 4.4 4.9 4.8 ...
>  .. ..- attr(*, "dimnames")=List of 2
>  .. .. ..$ : chr [1:130] "1" "2" "4" "5" ...
>  .. .. ..$ : chr [1:4] "Sepal.Length" "Sepal.Width" "Petal.Length" "Petal.Width"
>  .. ..- attr(*, "assign")= int [1:4] 1 2 3 4
>  ..@ kcall   : language kpca(x = x, data = ..1, kernel = "rbfdot", kpar = ..3, features = 2)
>  ..@ terms   :Classes 'terms', 'formula' length 2 ~Sepal.Length + Sepal.Width + Petal.Length + Petal.Width
>  .. .. ..- attr(*, "variables")= language list(Sepal.Length, Sepal.Width, Petal.Length, Petal.Width)
>  .. .. ..- attr(*, "factors")= int [1:4, 1:4] 1 0 0 0 0 1 0 0 0 0 ...
>  .. .. .. ..- attr(*, "dimnames")=List of 2
>  .. .. .. .. ..$ : chr [1:4] "Sepal.Length" "Sepal.Width" "Petal.Length" "Petal.Width"
>  .. .. .. .. ..$ : chr [1:4] "Sepal.Length" "Sepal.Width" "Petal.Length" "Petal.Width"
>  .. .. ..- attr(*, "term.labels")= chr [1:4] "Sepal.Length" "Sepal.Width" "Petal.Length" "Petal.Width"
>  .. .. ..- attr(*, "order")= int [1:4] 1 1 1 1
>  .. .. ..- attr(*, "intercept")= num 0
>  .. .. ..- attr(*, "response")= int 0
>  .. .. ..- attr(*, ".Environment")=<environment: R_GlobalEnv> 
>  .. .. ..- attr(*, "predvars")= language list(Sepal.Length, Sepal.Width, Petal.Length, Petal.Width)
>  .. .. ..- attr(*, "dataClasses")= Named chr [1:4] "numeric" "numeric" "numeric" "numeric"
>  .. .. .. ..- attr(*, "names")= chr [1:4] "Sepal.Length" "Sepal.Width" "Petal.Length" "Petal.Width"
>  ..@ n.action: NULL
> 	[[alternative HTML version deleted]]
> 
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.



More information about the R-help mailing list