[R] predict.kohonen for SOM returns NA?

Tidal Wave t1dalwav3 at gmail.com
Tue Mar 30 05:23:28 CEST 2010


All,

The kohonen predict function is returning NA for SOM predictions
regardless of data used... even the package example for a SOM using
wine data is returning NA's
Does anyone have a working example SOM. Also, what is the purpose of
trainY, what would be the dependent data for an unsupervised SOM?
As may be apparent to you by my questions, I am very new to kohonen
maps and am very grateful for any assistance offered. Thanks in
advance!
Below is terminal output:
> sessionInfo()
R version 2.10.1 (2009-12-14)
i386-pc-mingw32

locale:
[1] LC_COLLATE=English_United States.1252  LC_CTYPE=English_United
States.1252    LC_MONETARY=English_United States.1252
[4] LC_NUMERIC=C                           LC_TIME=English_United
States.1252

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base

other attached packages:
[1] kohonen_2.0.5 class_7.3-1

loaded via a namespace (and not attached):
[1] tools_2.10.1

> data(wines)
> set.seed(7)
> training <- sample(nrow(wines), 120)
> Xtraining <- scale(wines[training, ])
> Xtest <- scale(wines[-training, ],
+ center = attr(Xtraining, "scaled:center"),
+ scale = attr(Xtraining, "scaled:scale"))
> som.wines <- som(Xtraining, grid = somgrid(5, 5, "hexagonal"))
> som.prediction <- predict(som.wines, newdata = Xtest,
+ trainX = Xtraining,
+ trainY = factor(wine.classes[training]))
> table(wine.classes[-training], som.prediction$prediction)

  1
  2
  3
> som.prediction$prediction
 [1] NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA
NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA
NA
[47] NA NA NA NA NA NA NA NA NA NA NA
>



More information about the R-help mailing list