3

I'm trying to figure out a bit the mechanics behind how "R" handles factors as a predictor variable. None of which I write below perhaps is good practice, but, it is out of sheer curiosity, so would appreciate any thoughts. The standard Iris dataset in R has columns: Sepal.Length, Sepal.Width, Petal.Length, Petal.Width, Species, of which the last is a factor. The standard thing to do with this dataset is to demonstrate classification algorithms by say using a neural net or tree, where

rnn1 <- rxNeuralNet(Species~Sepal.Length+Sepal.Width+...,data = iris, numHiddenNodes = 100, numIterations = 1000,type = "classification")

I decided to see what would happen if you reverse this to:

rnn2 <- rnn1 <- rxNeuralNet(Petal.Width~Sepal.Length+Sepal.Width+Species,data = iris, numHiddenNodes = 100, numIterations = 1000,type = "regression")

I then created my test data-frame:

df1 <- data.frame(Petal.Width=5,Sepal.Length=12,Sepal.Width=3,Species="setosa",Petal.Length=3)

rxPredict() then gives me a score of 0.6058862 for species "setosa". But, very strangely, and this is my question, I can put any "string" I want for species, and I'll still get a prediction. I put Species="Jack", and rxPredict now gives a score of 1.545223. This is weird because in standard-R, it will throw a factor error if you try to predict against any factors that weren't in the original dataset.

Any ideas?

Thanks.

  • I think you need to add `factor(Species)` wherever `Species` appears in your rnn2/rnn1 models – sweetmusicality Jun 22 '17 at 18:57
  • Yes. I tried that as well, exactly the same results! – Dr. Ikjyot Singh Kohli Jun 22 '17 at 18:59
  • Seems as though one might want to remove the [R] tag since there is no package on CRAN with a function named rxNeuralNet – IRTFM Jun 22 '17 at 21:00
  • Hi. I left the R tag there because I was comparing with the nnet() output which of course is on CRAN. – Dr. Ikjyot Singh Kohli Jun 22 '17 at 21:02
  • I was being just a bit sarcastic. I don't think the question is really mis-tagged. But I do think you ought to make clear that you can only get this from the Microsoft server and it may even need to have the Revo-Open-R. At the moment that's not really clear. – IRTFM Jun 22 '17 at 22:01

0 Answers0