2

I am using the package caret to train a nnet classification model. The default sigmoid(logistic) transfer function works well. I was trying to use linear transfer function to do some comparisons. But I got an error.

The interesting thing I found is: if the target variable has more than 2 classes, the linear transfer function is OK; but if the target variable has 2 classes, it fails.

Here are some sample codes:

library(caret)
data(iris)

#This modeling works well. Species has 3 classes
model <- train(Species~., data=iris, method='nnet', linout=T, trControl=trainControl(method='cv'))

#Subset the dataset s.t. only two levels left for Species.
iris1 <- iris[1:100,]
iris1 <- droplevels(iris1)
model1 <- train(Species~., data=iris1, method='nnet', linout=T, trControl=trainControl(method='cv'))

Here is the error message:

Something is wrong; all the Accuracy metric values are missing:
    Accuracy       Kappa    
 Min.   : NA   Min.   : NA  
 1st Qu.: NA   1st Qu.: NA  
 Median : NA   Median : NA  
 Mean   :NaN   Mean   :NaN  
 3rd Qu.: NA   3rd Qu.: NA  
 Max.   : NA   Max.   : NA  
 NA's   :9     NA's   :9    
Error in train.default(x, y, weights = w, ...) : Stopping

I don't know what is the problem. Any suggestions? Thanks!

milos.ai
  • 3,882
  • 7
  • 31
  • 33
Leon
  • 21
  • 1
  • 2

1 Answers1

1

You also have 50 warnings: entropy fit only for logistic units

Your code works if you set the linout to False. Linout set to True switches for linear output units, which is not what your dataset is about. Even nnet with this settings will give you an error with iris1.

Lets use a simple nnet statement nnet(Species~., data=iris1, size = 1, linout = T) returns an error

Error in nnet.default(x, y, w, entropy = TRUE, ...) : entropy fit only for logistic units

which is roughly the warning from caret.

phiver
  • 23,048
  • 14
  • 44
  • 56
  • Sorry, I am confused. You said "Linout set to True switches to logistic units". But from the package document: The default value for linout is FALSE, which means logistic units. – Leon Dec 17 '15 at 19:42