i am trying to the neural network method on my data and i am stuck. i am allways getting the message:
in neurons[[i]] %*% weights[[i]] : requires numeric/complex matrix/vector arguments
the facts are:
- i am reading my data using
read.csvi am adding a link to a file with some of my data, i hope it helps https://www.dropbox.com/s/b1btx0cnhmj229p/collineardata0.4%287.2.2017%29.csv?dl=0 - i have no NA in my data (i checked twice)
the outcome of
str(data)is:'data.frame': 20 obs. of 457 variables: $ X300.5_alinine.sulphate : num 0.351 0.542 0.902 0.656 1 ... $ X300.5_bromocresol.green : num 0.435 0.603 0.749 0.314 0.922 ... $ X300.5_bromophenol.blue : num 0.415 0.662 0.863 0.345 0.784 ... $ X300.5_bromothymol.blue : num 0.2365 0.0343 0.4106 0.3867 0.8037 ... $ X300.5_chlorophenol.red : num 0.465 0.1998 0.7786 0.0699 1 ... $ X300.5_cresol.red : num 0.534 0.311 0.678 0.213 0.821 ... continued
i have tried to do use model.matrix
- the code i have was tried on different datasets (i.e iris) and it was good.
can anyone please try and suggest what is wrong with my data/data reading?
the code is
require(neuralnet)
require(MASS)
require(grid)
require(nnet)
#READ IN DATA
data<-read.table("data.csv", sep=",", dec=".", head=TRUE)
dim(data)
# Create Vector of Column Max and Min Values
maxs <- apply(data[,3:459], 2, max)
mins <- apply(data[,3:459], 2, min)
# Use scale() and convert the resulting matrix to a data frame
scaled.data <- as.data.frame(scale(data[,3:459],center = mins, scale = maxs - mins))
# Check out results
print(head(scaled.data,2))
#create formula
feats <- names(scaled.data)
# Concatenate strings
f <- paste(feats,collapse=' + ')
f <- paste('data$Type ~',f)
# Convert to formula
f <- as.formula(f)
f
#creating neural net
nn <- neuralnet(f,model,hidden=c(21,15),linear.output=FALSE)
str(scaled.data)
apply(scaled.data,2,function(x) sum(is.na(x)))