R机器学习-神经网络软件包

时间:2019-02-01 21:22:41

标签: r machine-learning neural-network deep-learning recurrent-neural-network

我具有结构化数据,如下所示:

> str(df.train)
'data.frame':   124 obs. of  11 variables:
 $ predictor01            : int  6 3 2 10 1 5 0 1 11 9 ...
 $ predictor02            : int  148 78 197 168 189 166 118 115 143 171 ...
 $ predictor03            : int  72 50 70 74 60 72 84 70 94 110 ...
 $ predictor04            : int  35 32 45 0 23 19 47 30 33 24 ...
 $ predictor05            : int  0 88 543 0 846 175 230 96 146 240 ...
 $ predictor06            : num  33.6 31 30.5 38 30.1 25.8 45.8 34.6 36.6 45.4 ...
 $ predictor07            : num  0.627 0.248 0.158 0.537 0.398 0.587 0.551 0.529 0.254 0.721 ...
 $ predictor08            : int  50 26 53 34 59 51 31 32 51 54 ...
 $ class-target          : Factor w/ 2 levels "Sem_diabetes",..: 2 2 2 2 2 2 2 2 2 2 ...
 $ class-target-binaray1 : logi  TRUE TRUE TRUE TRUE TRUE TRUE ...
 $ class-target-binaray2 : logi  FALSE FALSE FALSE FALSE FALSE FALSE ...

这是他们的摘要:

predictor01         predictor02        predictor03         predictor04        predictor05         predictor06          
 Min.   : 0.000000   Min.   :  0.0000   Min.   :  0.00000   Min.   : 0.00000   Min.   :  0.00000   Min.   : 0.00000  
 1st Qu.: 1.000000   1st Qu.:102.0000   1st Qu.: 64.75000   1st Qu.: 0.00000   1st Qu.:  0.00000   1st Qu.:26.97500  
 Median : 3.000000   Median :124.0000   Median : 72.00000   Median :25.00000   Median :  0.00000   Median :33.20000  
 Mean   : 3.725806   Mean   :127.6371   Mean   : 69.98387   Mean   :22.37903   Mean   : 78.41129   Mean   :32.90242  
 3rd Qu.: 6.000000   3rd Qu.:151.2500   3rd Qu.: 80.50000   3rd Qu.:34.00000   3rd Qu.:131.25000   3rd Qu.:37.40000  
 Max.   :14.000000   Max.   :197.0000   Max.   :110.00000   Max.   :63.00000   Max.   :846.00000   Max.   :67.10000  
 predictor07        predictor08        class-target      class-target-binaray1       class-target-binaray2   
 Min.   :0.078000   Min.   :21.00000   Target1     :62   Mode :logical               Mode :logical  
 1st Qu.:0.262500   1st Qu.:23.75000   Target2     :62   FALSE:62                    FALSE:62       
 Median :0.407000   Median :27.50000                     TRUE :62                    TRUE :62       
 Mean   :0.495871   Mean   :32.20161                                                    
 3rd Qu.:0.657500   3rd Qu.:39.50000                                                    
 Max.   :2.420000   Max.   :67.00000  

我是通过...创建模板的。

 mod.rn <- neuralnet( class-target-binaray1 + class-target-binaray2 ~ predictor01 +  predictor03 + predictor04 +
                         predictor05 + predictor06 + predictor07, 
                         df.train, hidden=4,
                         linear.output = TRUE, stepmax=1e6)

到此为止。

然后,我将生成的模型应用于测试数据,这样做:

test_result <- compute(mod.rn, df.test[,1:8])

测试数据结构与训练相同。所以我做了[,1:8]只选择了预测变量。

当我运行上面的最后一条命令时,收到以下错误消息:

Error in neurons[[i]] %*% weights[[i]] : argumentos não compatíveis

有什么想法吗?

1 个答案:

答案 0 :(得分:0)

您似乎没有为模型配备8个预测变量-predictor02中缺少predictor08neuranet()

尝试显式地仅保留相关的预测变量,即:

myvars <- c('predictor01', 'predictor03', 'predictor04', 'predictor05', 'predictor06', 'predictor07')
test_result <- compute(mod.rn, df.test[myvars])

或者,如果您只是错误地省略了这两个预测变量,请将它们重新添加到neuralnet()定义中,您的代码应该可以正常工作。