neuralnet预测返回相同的值,所有的预测(neuralnet prediction retur

2019-07-22 16:27发布

I'm trying to build a neural net with the neuralnet package and I'm having some trouble with it. I've been successful with the nnet package but no luck with the neuralnet one. I have read the whole documentation package and can't find the solution, or maybe I'm not able to spot it.

The training command I'm using is

nn<-neuralnet(V15 ~ V1 + V2 + V3 + V4 + V5 + V6 + V7 + V8 + V9 + V10 + V11 + V12 + V13 + V14,data=test.matrix,lifesign="full",lifesign.step=100,hidden=8) 

and for prediction

result<- compute(nn,data.matrix)$net.result

The training takes a whole lot longer than the nnet training. I have tried using the same algorithm as nnet (backpropagation instead of resilent backpropagation) and nothing, changed the activation function too (and the linear.output=F) and pretty much everything else, and the result didn't improved. Predicted values are all the same. I don't understand why the nnet works for me, while the neuralnet one doesn't.

I could really use some help, my (lack of) understanding of both things (neural nets and R) it's probably the cause, but can't find why.

My dataset is from UCI. I want to use the neural network for a binary classification. A sample of the data would be:

25,Private,226802,11th,7,Never-married,Machine-op-inspct,Own-child,Black,Male,0,0,40,United-States,<=50K.
38,Private,89814,HS-grad,9,Married-civ-spouse,Farming-fishing,Husband,White,Male,0,0,50,United-States,<=50K.
28,Local-gov,336951,Assoc-acdm,12,Married-civ-spouse,Protective-serv,Husband,White,Male,0,0,40,United-States,>50K.
44,Private,160323,Some-college,10,Married-civ-spouse,Machine-op-inspct,Husband,Black,Male,7688,0,40,United-States,>50K.
18,?,103497,Some-college,10,Never-married,NA,Own-child,White,Female,0,0,30,United-States,<=50K.
34,Private,198693,10th,6,Never-married,Other-service,Not-in-family,White,Male,0,0,30,United-States,<=50K.
29,?,227026,HS-grad,9,Never-married,?,Unmarried,Black,Male,0,0,40,United-States,<=50K.
63,Self-emp-not-inc,104626,Prof-school,15,Married-civ-spouse,Prof-specialty,Husband,White,Male,3103,0,32,United-States,>50K.
24,Private,369667,Some-college,10,Never-married,Other-service,Unmarried,White,Female,0,0,40,United-States,<=50K.
55,Private,104996,7th-8th,4,Married-civ-spouse,Craft-repair,Husband,White,Male,0,0,10,United-States,<=50K.
65,Private,184454,HS-grad,9,Married-civ-spouse,Machine-op-inspct,Husband,White,Male,6418,0,40,United-States,>50K.
36,Federal-gov,212465,Bachelors,13,Married-civ-spouse,Adm-clerical,Husband,White,Male,0,0,40,United-States,<=50K.
26,Private,82091,HS-grad,9,Never-married,Adm-clerical,Not-in-family,White,Female,0,0,39,United-States,<=50K.

Converted into a matrix, with the factors as numerical values:

V1  V2  V3  V4  V5  V6  V7  V8  V9  V10 V11 V12 V13 V14 V15
39  7   77516   10  13  5   1   2   5   2   2174    0   40  39  0
50  6   83311   10  13  3   4   1   5   2   0   0   13  39  0
38  4   215646  12  9   1   6   2   5   2   0   0   40  39  0
53  4   234721  2   7   3   6   1   3   2   0   0   40  39  0
28  4   338409  10  13  3   10  6   3   1   0   0   40  5   0
37  4   284582  13  14  3   4   6   5   1   0   0   40  39  0
49  4   160187  7   5   4   8   2   3   1   0   0   16  23  0
52  6   209642  12  9   3   4   1   5   2   0   0   45  39  1
31  4   45781   13  14  5   10  2   5   1   14084   0   50  39  1
42  4   159449  10  13  3   4   1   5   2   5178    0   40  39  1
37  4   280464  16  10  3   4   1   3   2   0   0   80  39  1
30  7   141297  10  13  3   10  1   2   2   0   0   40  19  1
23  4   122272  10  13  5   1   4   5   1   0   0   30  39  0

Summary of the predicted values:

      V1           
 Min.   :0.2446871  
 1st Qu.:0.2446871  
 Median :0.2446871  
 Mean   :0.2451587  
 3rd Qu.:0.2446871  
 Max.   :1.0000000  

Value of the Wilcoxon-Mann-Whitney test (area under the curve) shows that the prediction performance is virtualy the same as a random.

performance(predneural,"auc")@y.values
[1] 0.5013319126

Answer 1:

当你得到奇怪的结果与神经网络要考虑的第一个原因是正常化。 您的数据必须是标准化的,否则,是的,训练将导致扭曲NN这将产生相同的结果,所有的时间,它是一种常见的症状。

看着你的数据集,也有价值观>> 1,这意味着他们都是由神经网络处理基本相同。 其原因是外部周围0一些范围的传统上使用的响应函数是(几乎)恒定。

馈入神经网络之前,一定要规范你的数据



Answer 2:

类似于从@sashkello答案,我面对前面一个类似的问题时,我的数据是不正确标准化。 有一次,我归数据一切正常运行。

最近,我再次面对这个问题,并调试完毕后,我发现有可能是另一个原因,给予同样的输出神经网络。 如果您有具有权重衰减项神经网络,例如,在RSNNS包,请确保您的衰减项是不是如此之大,所有的权重去基本上为0。

我在R.使用插入符包最初,我使用的衰变超参数= 0.01。 当我看着诊断,我看到正在计算每个倍(交叉验证)的RMSE,但Rsquared总是NA。 在这种情况下,所有的预测都出来为相同的值。

一旦我的衰减减小到低得多的值(1E-5和下部),我得到了预期的结果。

我希望这有帮助。



文章来源: neuralnet prediction returns the same values for all predictions