Reputation: 223
I am trying to implement a basic neural network
library (neuralnet)
set.seed(2016)
attribute <- as.data.frame(sample(seq(-2,2, length =50),50, replace = FALSE ),ncol =1)
response <- attribute ^2
data <- cbind ( attribute , response)
colnames(data) <- c(" attribute "," response")
head (data ,10)
fit <- neuralnet(response~attribute, data = data,hidden =c(3 ,3),threshold =0.01)
testdata <- as.matrix(sample(seq(-2,2,length =10), 10, replace = FALSE ), ncol =1)
pred <- compute(fit , testdata)
result <- cbind (testdata , pred $net.result, testdata ^2)
colnames (result) <- c(" Attribute ","Prediction ", " Actual ")
round (result ,4)
I am getting the following error for neuralnet command
Error in model.frame.default(formula.reverse, data) :invalid type (list) for variable 'attribute'
Can someone explain how this can be resolved ? Thanks
Upvotes: 0
Views: 563
Reputation: 345
Space in the name of the "attribute" while assigning name colnames(data) <- c(" attribute "," response")
Remove it extra space & it works fine colnames(data) <- c("attribute","response")
Upvotes: 2