Error in Computing confusion matrix

r

#1

Hi

Hi,

I am facing following issues while computing Confusion matrix after building the model using Neuralnet. Appreciate your quick help to resolve the issue :

I am attaching the dataset here : Project-Attrition.csv (111.0 KB)

Mentioned below is the R code used :

R code :
 library(NeuralNetTools)
 #Read the data for train and test data 
CTDF = read.csv("Project-Attrition.csv",header=T,na.strings=c(""))
# Let us set differnt seeds and extract 70 % of Poulation for arriving ar Development, Test and       Holdout samples
CTDF.dev  = sample.split(CTDF$Target,SplitRatio=0.70)
head(split,20)
CTDF.train= subset(CTDF, split== TRUE)
str(CTDF.train)
View(CTDF.train)
table(CTDF.train$Target)
CTDF.test= subset(CTDF, split== FALSE)
str(CTDF.test)
table(CTDF.test$Target)
CTDF.NND=CTDF.train
CTDF.NNT=CTDF.test
    Model=nnet(Target~Dailyrate+DFrmHome+Education+Employeecount+Age+HourlyRate+Jobinvolvment+Joblevel, data=CTDF.NND, size=30, rang= 0.1, decay = 5e-4 , maxit = 500)
    table(Actual=CTDF.NND$Target, Prediction=predict(Model, data=CTDF.NND))
    CTDF.NNT$predict.class = predict(Model, CTDF.NNT) 
    confusionMatrix(CTDF.NNT$predict.class, CTDF.NNT$Target)

Output :

For table(Actual=CTDF.NND$Target, Prediction=predict(Model, data=CTDF.NND))
I was expecting a confusion matrix like below.
    0    1 
0 
1
However what I have got is : 
**************************************************************************
       Prediction
Actual 0.00892725347390036 0.0358546806229366 0.0376897872686173 0.10518235583921 0.124456456913317
     0                   3                242                  1               34               197
     1                   0                  9                  0                4                28
      Prediction
Actual 0.1363541434416 0.236290782608584 0.286744920923175 0.331511427682813 0.613818492677834 0.726882504157994
     0              19                42                 5               474                51                 6
     1               3                13                 2               235                81                16
      Prediction
******************************************************************************

Also for test data for computing the confusion matrix I am getting the following errors: 
confusionMatrix(CTDF.NNT$predict.class, CTDF.NNT$Target)
Error in confusionMatrix.default(CTDF.NNT$predict.class, CTDF.NNT$Target) : 
  the data cannot have more levels than the reference

Please help in overcoming these issues.