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!