user2912902
user2912902

Reputation: 337

using softmax in nnet R for target column with more than 2 states

I am using the nnet package for classification of a target column with 3 states

model <- nnet(targetcolumn ~ ., data=DATAFRAME)

But I want it to use entropy instead of default softmax and when I set softmax=false , it fails with the error :

model <- nnet(targetcolumn ~ ., data=DATAFRAME, maxit=1000, MaxNWts=10000,softmax=FALSE, entropy=TRUE)

Error in nnet.default(x, y, w, softmax = false, ...) : 
  formal argument "softmax" matched by multiple actual arguments

Is there a way to somehow use entropy modelling in this scenario?

Upvotes: 3

Views: 3896

Answers (1)

lorelai
lorelai

Reputation: 147

# because you've got a classification problem it is imperative that
softmax=TRUE

#to calculate the entropy
entropy=TRUE

But before these 2 work together it is necessary that you transform your Y (0 1 2 ...) into a matrix of dummy variables. This is done by:

dataframe$Y = class.ind(dataframe$targetcolumn)

# delete the old target variable
dataframe$targetcolumn=NULL

# and now you can start creating your ANN
nnet1 = nnet (Y~., dataframe, size=..., decay=..., entropy=TRUE, softmax=TRUE)

Upvotes: 3

Related Questions