r - Error running neural net -


library(nnet) set.seed(9850) train1<- sample(1:155,110) test1 <- setdiff(1:110,train1) ideal <- class.ind(hepatitis$class) hepatitisann = nnet(hepatitis[train1,-20], ideal[train1,], size=10, softmax=true) j <- predict(hepatitisann, hepatitis[test1,-20], type="class") hepatitis[test1,]$class table(predict(hepatitisann, hepatitis[test1,-20], type="class"),hepatitis[test1,]$class) confusionmatrix(hepatitis[test1,]$class, j) 

error:

error in nnet.default(hepatitis[train1, -20], ideal[train1, ], size = 10,  :    na/nan/inf in foreign function call (arg 2) in addition: warning message: in nnet.default(hepatitis[train1, -20], ideal[train1, ], size = 10,  :   nas introduced coercion  hepatitis variable consists of hepatitis dataset available on uci. 

this error message because have character values in data.

try reading hepatitis dataset na.strings = "?". defined in description of dataset on uci page.

headers <- c("class","age","sex","steroid","antivirals","fatigue","malaise","anorexia","liver big","liver firm","spleen palpable","spiders","ascites","varices","bilirubin","alk phosphate","sgot","albumin","protime","histology") hepatitis <- read.csv("https://archive.ics.uci.edu/ml/machine-learning-databases/hepatitis/hepatitis.data", header = false, na.strings = "?") names(hepatitis) <- headers  library(nnet) set.seed(9850) train1<- sample(1:155,110) test1 <- setdiff(1:110,train1)  ideal <- class.ind(hepatitis$class)  # give error due missing values # 1st column of hepatitis dataset class variable hepatitisann <- nnet(hepatitis[train1,-1], ideal[train1,], size=10, softmax=true) 

this code not give error, give error on missing values. need address before can continue. aware class variable first variable in dataset straight uci data repository

edit based on comments:

the na.action works if use formula notation of nnet. in case:

hepatitisann <- nnet(class.ind(class)~., hepatitis[train1,], size=10,  softmax=true, na.action = na.omit) 

Comments

Popular posts from this blog

javascript - Slick Slider width recalculation -

jsf - PrimeFaces Datatable - What is f:facet actually doing? -

angular2 services - Angular 2 RC 4 Http post not firing -