0

I have been trying to run an example code for supervised kohonen SOMs from https://clarkdatalabs.github.io/soms/SOM_NBA . When I tried to predict test set data I got the following error:

pos.prediction <- predict(NBA.SOM3, newdata = NBA.testing)
Error in FUN(X[[i]], ...) : 
Data type not allowed: should be a matrix or a factor

I tried newdata = as.matrix(NBA.testing) but it did not help. Neither did as.factor().

Why does it happen? And how can I fix that?

  • can you show the `class(NBA.testing)`? And repeat that once you've converted to a matrix/factor to check that it has transformed correctly? – morgan121 Dec 05 '18 at 05:51
  • @RAB > class(NBA.testing) [1] "matrix" class( as.matrix(NBA.testing)) [1] "matrix" > typeof( as.matrix(NBA.testing)) [1] "double" – Kirill Klimenko Dec 05 '18 at 09:22
  • hmm, why is it a double in the last example...maybe thats the issue? – morgan121 Dec 05 '18 at 12:21
  • @RAB it is double because I used typeof() to provide additional information on data type. Double means the same as numeric and it should be acceptable – Kirill Klimenko Dec 05 '18 at 19:57

1 Answers1

1

You should put one more argument to the predict function, i.e. "whatmap", then set its value to 1. The code would be like:

pos.prediction <- predict(NBA.SOM3, newdata = NBA.testing, whatmap = 1)

To verify the prediction result, you can check using:

table(NBA$Pos[-training_indices], pos.prediction$predictions[[2]], useNA = 'always')

The result may be different from that of the tutorial, since it did not declare the use of set.seed() function. I suggest that the set.seed() with an arbitrary number in it was declared somewhere before the training phase. For simplicity, put it once on the top most of your script, e.g.

set.seed(12345)

This will guarantee a reproducible result of your model next time you re-run your script.

Hope that will help.

h45
  • 206
  • 1
  • 6