我正在尝试实现一个基本的神经网络
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)
我收到了神经网络命令的以下错误
Error in model.frame.default(formula.reverse, data) :invalid type (list) for variable 'attribute'
有人可以解释如何解决这个问题吗?感谢
答案 0 :(得分:2)
分配名称时“属性”名称中的空格 colnames(data)&lt; - c(“attribute”,“response”)
删除额外空间&amp;它工作正常 colnames(data)&lt; - c(“attribute”,“response”)