R

时间:2016-07-18 03:30:10

标签: r machine-learning neural-network

我试图在R中编写一个神经网络,我收到的错误表明

  

神经元[[i]]%*%权重[[i]]出错:需要数字/复杂矩阵/向量参数。

这一步发生在这一步之后:

nn<-neuralnet(formula,data=train,hidden=10,threshold=0.01)

有人可以解释一下这意味着什么吗?我对R来说相当新,所以我并没有真正理解类似问题的答案。我将附上以下代码。提前致谢!

library(neuralnet)

dat <- read.csv("/Users/Sean/Documents/Cintas Stock Trailing.csv", header = TRUE)

## Features slected after the feature selection
vars <- c("X50.calendar.day.moving.average","asset_matched", "Beta", "CTAS.Enterprise.Value..In.Millions..Basically.the.first.value.is.11.5.B.",
          "EBITDA_matched" , "invested_matched" , "Close..Nasdaq.", "Open..Nasdaq.", "Price.of.Oil",
          "return_matched", "X50.Day.Simple.Moving.Average..S.P.500.", "tobin_matched","zmi_matched",
          "PE.Ratio", "Indicator")
Ycolumn <- "Indicator"

alldata <- dat[, vars];
y <- alldata$Indicator;

##remove NA and data cleaning
alldata_new <- na.omit(alldata);
data<- alldata_new
rm(alldata_new)

##splitting the data into training and testing
index <- sample(1:nrow(data),round(0.90*nrow(data)))
train <- data[index,]
test <- data[-index,]

formula <- paste(Ycolumn,paste(vars,collapse=' + '),sep=' ~ ')



nn<-neuralnet(formula,data=train,hidden=10,threshold=0.01)
plot(nn)

pr.nn <- compute(nn,test_[,1:13])

pr.nn_ <- pr.nn$net.result*(max(data$medv)-min(data$medv))+min(data$medv)
test.r <- (test_$medv)*(max(data$medv)-min(data$medv))+min(data$medv)

MSE.nn <- sum((test.r - pr.nn_)^2)/nrow(test_)

以下是数据链接:

https://s3.amazonaws.com/iedu-attachments-message/ff398557faa9b034c9ab36cb200b049b_fd95a111761a10a8dec1203a47386578.csv

0 个答案:

没有答案