我使用neuralnet做bpn分析时,在显示预测结果出现Error in prediction$net.result : $ operator is invalid for atomic vectors,我已找过很多文章仍找不到解决方式,请问可以怎么做呢?! 以下是我的code另想请较这样的逻辑是否正确,谢谢
#资料标准化
maxs <- apply(data, 2, max)
mins <- apply(data, 2, min)
data1 <- as.data.frame(scale(data,center = mins, scale = maxs - mins))
bpn=neuralnet(formula = JS+TI~QA+QB+QC+QD+QE+QF+QG+QH+QI+QJ+QK+QL+QM+QN+QO+QP+QQ+QR+QS+QT,
data = data1, hidden = 2, learningrate = 0.01, algorithm = "backprop",
err.fct = "sse", linear.output = FALSE)
#资料分成训练与测试
smp.size <- floor(0.8*nrow(data1))
set.seed(131)
train.ind <- sample(seq_len(nrow(data1)), smp.size)
train <- data[train.ind, ]
test <- data[-train.ind, ]
#训练与测试资料标准化
maxst <- apply(train, 2, max)
minst <- apply(train, 2, min)
scaled.train <- as.data.frame(scale(train,center = mins, scale = maxs - mins))
maxst <- apply(test, 2, max)
minst <- apply(test, 2, min)
scaled.test <- as.data.frame(scale(test,center = mins, scale = maxs - mins))
#检视预测结果
prediction <- compute(bpn, scaled.test[, 1:20])$net.result
cbind(scaled.test, prediction)
prediction$net.result