Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/72.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R语言中神经网络的训练_R_Neural Network_Classification_Training Data - Fatal编程技术网

R语言中神经网络的训练

R语言中神经网络的训练,r,neural-network,classification,training-data,R,Neural Network,Classification,Training Data,我试图训练一个神经网络,但得到了这个信息。你能告诉我为什么吗?是因为它应该是数字吗?如果缺少数据,我会打个问号。我应该换这个吗 > dataset <- read.csv("~/DATA630/ucidatasethouse-votes-84.data.csv") > trainset <- dataset[1:305, ] > testset <- dataset[306:435, ] > polpartynet <- neuralnet(Par

我试图训练一个神经网络,但得到了这个信息。你能告诉我为什么吗?是因为它应该是数字吗?如果缺少数据,我会打个问号。我应该换这个吗

> dataset <- read.csv("~/DATA630/ucidatasethouse-votes-84.data.csv")
> trainset <- dataset[1:305, ]
> testset <- dataset[306:435, ]
> polpartynet <- neuralnet(Party ~ HndcpInfants + WaterProject + AdoptBudget + DocFeeFreeze + ElSalvadorAid + ReligiousGroupsSchools + AntiSatellTestBan + AidNicaraguaContras + MXMissile + Immigration + SynCorpCutback + EducationSpending + SuperfundRighttoSue + Crime + DutyFreeExports + ExportAdminSouthAfrica, trainset, hidden = 4, lifesign = "minimal", linear.output = FALSE, threshold = 0.1)
hidden: 4    thresh: 0.1    rep: 1/1    steps: 
Error in neurons[[i]] %*% weights[[i]] : 
  requires numeric/complex matrix/vector arguments

变量的类别是什么?我想你可能已经想到了这一点,但如果一个不同的模型不合适的话,这也值得考虑。我还在学习术语。班我所有的变量都是因子。这有关系吗?我应该更改问号吗?>数据帧:435 obs。在17个变量中:$Party:Factor w/2级别“民主党”,“共和党”:2 2 1 2 1…$HndcpInfants:系数w/3级“?”,“n”,“y”:2 2 2 3$WaterProject:系数w/3级“?”,“n”,“y”:3 3 3神经网络自然与数值变量一起工作。当然,您可以对因子变量进行热编码并继续。但是既然你所有的变量都是因子,为什么你首先需要神经网络呢?方法是把它们转化为二元虚拟变量,其中因子的每一级都是一个单独的列。最好的方法是使用model.matrix,如中所述。或者,您可以使用包插入符号中的dummyVars函数。它是一个类赋值。我将切换n,y?对1、2、3和对-1和0的参与方。听起来怎么样?谢谢你的评论。
Party   HndcpInfants    WaterProject    AdoptBudget DocFeeFreeze    ElSalvadorAid   ReligiousGroupsSchools  AntiSatellTestBan   AidNicaraguaContras MXMissile   Immigration SynCorpCutback  EducationSpending   SuperfundRighttoSue Crime   DutyFreeExports ExportAdminSouthAfrica
1   n   y   n   y   y   y   n   n   n   y   ?   y   y   y   n   y
1   n   y   n   y   y   y   n   n   n   n   n   y   y   y   n   ?
2   ?   y   y   ?   y   y   n   n   n   n   y   n   y   y   n   n
2   n   y   y   n   ?   y   n   n   n   n   y   n   y   n   n   y
2   y   y   y   n   y   y   n   n   n   n   y   ?   y   y   y   y
2   n   y   y   n   y   y   n   n   n   n   n   n   y   y   y   y
2   n   y   n   y   y   y   n   n   n   n   n   n   ?   y   y   y
1   n   y   n   y   y   y   n   n   n   n   n   n   y   y   ?   y
1   n   y   n   y   y   y   n   n   n   n   n   y   y   y   n   y