首页 > 解决方案 > r中神经网络分类器中的未定义列

问题描述

我正在使用 r 程序为具有 100 个观察值和 3 个属性(x、y 和 z)的随机标准随机变量拟合神经网络分类器。当隐藏节点设置为 1 时,我需要在数据中有两个类并计算测试错误。

我写了下面的代码:

nObs <- 100
x <- matrix (rnorm (nObs), ncol =2)
y <- matrix (rnorm (nObs), ncol =2)
z <- matrix (rnorm (nObs), ncol =2)
xtest <- matrix (rnorm (2*nObs*2) , ncol =2)
ytest <- sample (c(-1,1) , 2*nObs, rep=TRUE)
ztest <- sample (c(-1,1) , 1.5*nObs, rep=TRUE)
xtest[ytest ==1,] <- xtest[ytest ==1,] + 1
xtest[ztest ==2,] <- xtest[ztest ==2,] + 2
testdat <- data.frame(x=xtest, y=as.factor(ytest))

data = data.frame(nObs)
y = factor(c(xtest,ytest,ztest))

library(neuralnet)
nnRes <- neuralnet(y~xtest+ytest+ztest,data=data,hidden=4,err.fct = "sse", linear.output = FALSE)
plot(nnRes)

我收到以下错误:

[.data.frame(data, , model.list$variables)中的错误:选择了未定义的列

为具有 3 个数据集的神经网络查找测试错误的正确方法是什么?

标签: rneural-network

解决方案


推荐阅读