r - Error while computing Confusion matrix - Neuralnet package -
data used (sample)
empn target dailyrate dfrmhom
empnumber target dailyrate dfrmhome education employeecount age hourlyrate jobinvolvment joblevel 1 0 1 1 1 -1 1 1 1 1 2 1 1 1 1 1 1 1 1 1 3 0 1 -1 1 1 -1 1 1 1 4 1 1 1 1 1 1 1 1 1 5 0 1 -1 1 1 -1 1 1 1 6 1 1 -1 1 1 -1 1 -1 1 7 0 1 1 1 -1 1 1 1 1 8 1 1 1 1 1 1 1 1 1 9 1 1 -1 1 1 -1 1 1 1 10 1 1 1 1 1 1 1 1 1 11 0 1 -1 1 -1 -1 1 1 1 12 0 1 1 1 -1 1 1 1 1 13 0 1 1 1 1 1 1 1 1 14 1 1 1 1 1 -1 1 1 1 15 1 1 1 1 1 1 1 1 1 16 1 1 -1 1 1 -1 1 -1 1 17 0 1 1 1 1 -1 1 1 1 18 0 1 -1 1 1 -1 1 1 1 19 0 1 1 1 -1 1 1 1 1 20 0 1 -1 1 1 -1 1 1 1 21 0 1 1 1 -1 1 1 1 1 22 0 1 1 1 -1 1 1 1 1
rcode : library(neuralnettools) #read data train , test data ctdf = read.csv("project-attrition.csv",header=t,na.strings=c("")) # let set differnt seeds , extract 70 % of poulation arriving @ development, test , 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 : str(ctdf.train) 'data.frame': 3167 obs. of 10 variables: $ empnumber : int 1 2 4 5 6 7 11 12 14 15 ... $ target : int 0 1 1 0 1 0 0 0 1 1 ... $ dailyrate : int 1 1 1 1 1 1 1 1 1 1 ... $ dfrmhome : int 1 1 1 -1 -1 1 -1 1 1 1 ... $ education : int 1 1 1 1 1 1 1 1 1 1 ... $ employeecount: int -1 1 1 1 1 -1 -1 -1 1 1 ... $ age : int 1 1 1 -1 -1 1 -1 1 -1 1 ... $ hourlyrate : int 1 1 1 1 1 1 1 1 1 1 ... $ jobinvolvment: int 1 1 1 1 -1 1 1 1 1 1 ... $ joblevel : int 1 1 1 1 1 1 1 1 1 1 ...
for "table(actual=ctdf.nnd$target, prediction=predict(model, data=ctdf.nnd))"
i expecting confusion matrix below. 0 1 0 1
however have got :
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 test data computing confusion matrix getting following errors:
confusionmatrix(ctdf.nnt$predict.class, ctdf.nnt$target)
error in confusionmatrix.default(ctdf.nnt$predict.class, ctdf.nnt$target) : data cannot have more levels reference
please in overcoming these issues.
Comments
Post a Comment