- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我一直在研究神经网络,并尝试利用 MATLAB 的神经网络工具箱和 Mathworks 提供的示例。到目前为止,我一直发现这个主题非常有趣。
我对 MATLAB 代码有基本的了解。然而,我一直无法理解一旦训练完成后如何将自己的测试数据输入到神经网络中。一旦网络训练完毕,Mathworks 中的示例似乎都结束了。
例如:http://in.mathworks.com/help/nnet/examples/wine-classification.html#zmw57dd0e324
上面的链接中有一个“测试神经网络”的部分,但没有给出有关所使用的测试数据的信息。
我意识到这可能是一个新手问题,但我希望能帮助理解这一点。
最佳答案
您可以使用神经网络工具箱中的 sim
命令。基本上,您将提交一个 M x N
矩阵,其中 M
是特征总数,N
是样本总数。 M
与您拥有的输入层神经元总数相关。因此,对于每个输入,您都需要在该矩阵中提供一列。
因此,一旦您训练了网络并且按照示例进行操作,您的神经网络就应该存储在 net
中。只需创建您的输入数据,并使用您所需的输入“模拟”神经网络。
因此,假设您的输入数据存储在 X
中,您将执行此操作:
Y = sim(net, X);
但是,如果您想了解神经网络在相同输入下的执行情况,请尝试使用变量 x
,因为这是输入数据存储在帖子中提到的数据集中的位置:
Y = sim(net, x);
<小时/>
或者,net
是一个可调用的对象。只需直接使用对象 net
即可实现与 sim
相同的功能:
Y = net(x);
<小时/>
如果您想做一个小测试,请尝试加载房价数据集:
[x,t] = house_dataset;
这将返回一个包含 13 个特征(行)的数据矩阵,并且有 506 个样本。它存储在矩阵x
中。向量t是输出层值,或者说是神经网络运行后的目标值。您可以使用包含 1 个隐藏层和 10 个神经元的网络来训练该数据集的神经网络,然后我们可以看到该神经网络在处理相同输入数据时的表现如何:
net = feedforwardnet(10);
net = train(net, x, t); %// Brings up NN Train Tool and trains
y = sim(net, x); %// Or y = net(x);
然后您可以并排显示结果并查看它们的比较情况
disp([y; t]);
顶行是预测值,底行是真实值:
Columns 1 through 7
23.1000 22.5739 34.6595 32.9133 33.3979 24.0131 19.6418
24.0000 21.6000 34.7000 33.4000 36.2000 28.7000 22.9000
Columns 8 through 14
19.3123 15.3914 18.8765 19.6154 18.8690 20.0817 18.0593
27.1000 16.5000 18.9000 15.0000 18.9000 21.7000 20.4000
Columns 15 through 21
17.4043 17.7989 19.4390 17.8489 18.5007 17.3547 14.3393
18.2000 19.9000 23.1000 17.5000 20.2000 18.2000 13.6000
Columns 22 through 28
16.9866 17.5983 15.2679 16.3294 13.2075 15.6425 14.3992
19.6000 15.2000 14.5000 15.6000 13.9000 16.6000 14.8000
Columns 29 through 35
18.8453 20.4586 14.5208 15.4776 12.6204 14.5306 12.2213
18.4000 21.0000 12.7000 14.5000 13.2000 13.1000 13.5000
Columns 36 through 42
21.5945 21.7292 21.3951 22.8980 29.5480 35.4459 33.3658
18.9000 20.0000 21.0000 24.7000 30.8000 34.9000 26.6000
Columns 43 through 49
24.9201 25.2191 22.0473 20.2307 21.9648 19.1073 16.4167
25.3000 24.7000 21.2000 19.3000 20.0000 16.6000 14.4000
Columns 50 through 56
19.1333 19.4673 19.6465 26.6304 20.6860 18.0080 34.7084
19.4000 19.7000 20.5000 25.0000 23.4000 18.9000 35.4000
Columns 57 through 63
23.9052 28.8725 23.2335 21.1107 18.5425 17.7766 22.5957
24.7000 31.6000 23.3000 19.6000 18.7000 16.0000 22.2000
Columns 64 through 70
24.6137 30.3093 24.5964 20.3996 21.0408 18.2597 19.9876
25.0000 33.0000 23.5000 19.4000 22.0000 17.4000 20.9000
Columns 71 through 77
25.4133 21.4175 22.4705 24.1181 25.2216 22.2482 20.4357
24.2000 21.7000 22.8000 23.4000 24.1000 21.4000 20.0000
Columns 78 through 84
21.7641 20.8850 20.6352 27.3050 22.6721 23.7894 21.7782
20.8000 21.2000 20.3000 28.0000 23.9000 24.8000 22.9000
Columns 85 through 91
24.1746 26.2748 22.9204 23.2649 27.7500 30.4014 23.7201
23.9000 26.6000 22.5000 22.2000 23.6000 28.7000 22.6000
Columns 92 through 98
23.1654 24.7010 25.0065 20.9675 26.6610 22.2313 41.1054
22.0000 22.9000 25.0000 20.6000 28.4000 21.4000 38.7000
Columns 99 through 105
43.3199 33.8214 22.5828 23.9000 19.4996 19.0978 19.2686
43.8000 33.2000 27.5000 26.5000 18.6000 19.3000 20.1000
Columns 106 through 112
17.6835 18.1297 19.9324 19.4827 18.8635 22.3501 23.0958
19.5000 19.5000 20.4000 19.8000 19.4000 21.7000 22.8000
Columns 113 through 119
19.2355 19.4148 21.4072 18.6230 21.0624 19.4977 19.8504
18.8000 18.7000 18.5000 18.3000 21.2000 19.2000 20.4000
Columns 120 through 126
19.7301 22.3515 21.7456 19.6909 17.3642 18.6674 21.4590
19.3000 22.0000 20.3000 20.5000 17.3000 18.8000 21.4000
Columns 127 through 133
15.7843 14.9932 19.6013 14.6810 19.5595 18.3563 18.6026
15.7000 16.2000 18.0000 14.3000 19.2000 19.6000 23.0000
Columns 134 through 140
15.2750 11.8104 18.7860 16.7552 19.7692 15.9850 17.8815
18.4000 15.6000 18.1000 17.4000 17.1000 13.3000 17.8000
Columns 141 through 147
18.1044 11.2998 13.7603 16.7915 14.2739 15.8247 12.1940
14.0000 14.4000 13.4000 15.6000 11.8000 13.8000 15.6000
Columns 148 through 154
14.8796 15.9726 17.0902 20.0606 12.5238 15.0568 15.3508
14.6000 17.8000 15.4000 21.5000 19.6000 15.3000 19.4000
Columns 155 through 161
16.8791 17.1680 7.5081 38.1429 27.6726 23.4515 33.1939
17.0000 15.6000 13.1000 41.3000 24.3000 23.3000 27.0000
Columns 162 through 168
49.9039 49.8868 49.4694 20.0338 20.5124 51.1646 19.0164
50.0000 50.0000 50.0000 22.7000 25.0000 50.0000 23.8000
Columns 169 through 175
23.1614 23.9231 18.1501 19.0578 24.0764 25.6909 24.2217
23.8000 22.3000 17.4000 19.1000 23.1000 23.6000 22.6000
Columns 176 through 182
29.0459 23.7307 24.3887 28.9583 36.7788 41.2092 29.0054
29.4000 23.2000 24.6000 29.9000 37.2000 39.8000 36.2000
Columns 183 through 189
36.1596 29.3311 24.9179 26.8610 46.6416 30.5403 29.2822
37.9000 32.5000 26.4000 29.6000 50.0000 32.0000 29.8000
Columns 190 through 196
32.3537 30.5739 28.0238 33.5408 32.5201 30.3314 47.7960
34.9000 37.0000 30.5000 36.4000 31.1000 29.1000 50.0000
Columns 197 through 203
35.5760 29.9340 32.4614 23.7173 24.6185 22.3271 40.2040
33.3000 30.3000 34.6000 34.9000 32.9000 24.1000 42.3000
Columns 204 through 210
48.7640 51.9776 21.6903 23.1472 19.7713 20.8484 19.3971
48.5000 50.0000 22.6000 24.4000 22.5000 24.4000 20.0000
Columns 211 through 217
19.2595 20.7310 21.9656 24.4268 23.4818 22.6366 23.3319
21.7000 19.3000 22.4000 28.1000 23.7000 25.0000 23.3000
Columns 218 through 224
27.5792 19.9003 21.9243 27.6622 25.8529 27.0425 26.9247
28.7000 21.5000 23.0000 26.7000 21.7000 27.5000 30.1000
Columns 225 through 231
43.9926 46.3891 41.9625 31.2884 42.9222 31.0752 24.0971
44.8000 50.0000 37.6000 31.6000 46.7000 31.5000 24.3000
Columns 232 through 238
33.9499 45.8143 44.0646 27.7080 24.5834 24.8484 33.5038
31.7000 41.7000 48.3000 29.0000 24.0000 25.1000 31.5000
Columns 239 through 245
27.1918 25.1814 24.1256 18.9528 20.8431 27.5930 15.9916
23.7000 23.3000 22.0000 20.1000 22.2000 23.7000 17.6000
Columns 246 through 252
15.4457 21.3048 18.9629 22.2684 26.9249 26.6310 28.3915
18.5000 24.3000 20.5000 24.5000 26.2000 24.4000 24.8000
Columns 253 through 259
31.1707 42.3749 21.8852 20.0264 41.3473 51.4709 37.5230
29.6000 42.8000 21.9000 20.9000 44.0000 50.0000 36.0000
Columns 260 through 266
31.7275 35.0836 40.2452 48.8115 34.8549 36.0551 21.6751
30.1000 33.8000 43.1000 48.8000 31.0000 36.5000 22.8000
Columns 267 through 273
30.0784 48.2556 43.5570 21.8858 19.8884 23.6277 24.2718
30.7000 50.0000 43.5000 20.7000 21.1000 25.2000 24.4000
Columns 274 through 280
36.2902 33.7512 31.2525 32.4099 33.0711 26.3885 36.7014
35.2000 32.4000 32.0000 33.2000 33.1000 29.1000 35.1000
Columns 281 through 287
45.9504 36.7908 46.8473 51.1511 31.4501 23.5448 21.8759
45.4000 35.4000 46.0000 50.0000 32.2000 22.0000 20.1000
Columns 288 through 294
23.4287 22.6450 25.2664 32.6864 35.8508 30.2136 23.6842
23.2000 22.3000 24.8000 28.5000 37.3000 27.9000 23.9000
Columns 295 through 301
21.9361 29.8485 27.2524 20.1174 23.8767 30.0819 26.0127
21.7000 28.6000 27.1000 20.3000 22.5000 29.0000 24.8000
Columns 302 through 308
24.2473 26.5010 32.4189 34.7875 28.9162 35.5226 30.2009
22.0000 26.4000 33.1000 36.1000 28.4000 33.4000 28.2000
Columns 309 through 315
24.1533 19.4709 18.2852 22.0597 19.2040 20.6719 22.5350
22.8000 20.3000 16.1000 22.1000 19.4000 21.6000 23.8000
Columns 316 through 322
17.3670 19.0604 19.3382 22.5443 21.3041 23.1810 22.7061
16.2000 17.8000 19.8000 23.1000 21.0000 23.8000 23.1000
Columns 323 through 329
20.5965 18.3056 23.5467 24.9056 22.9716 21.5595 21.3041
20.4000 18.5000 25.0000 24.6000 23.0000 22.2000 19.3000
Columns 330 through 336
25.0149 21.6011 16.6778 20.7220 23.1595 23.1583 21.2709
22.6000 19.8000 17.1000 19.4000 22.2000 20.7000 21.1000
Columns 337 through 343
20.5881 20.0957 22.1791 21.6646 20.9052 32.2760 19.6094
19.5000 18.5000 20.6000 19.0000 18.7000 32.7000 16.5000
Columns 344 through 350
26.6120 30.8497 18.2102 17.3026 24.0279 27.7069 28.6764
23.9000 31.2000 17.5000 17.2000 23.1000 24.5000 26.6000
Columns 351 through 357
24.0160 22.8876 19.0665 27.5481 18.8396 20.1889 17.1304
22.9000 24.1000 18.6000 30.1000 18.2000 20.6000 17.8000
Columns 358 through 364
19.3401 22.0580 20.7871 25.3794 19.9338 23.0456 20.1196
21.7000 22.7000 22.6000 25.0000 19.9000 20.8000 16.8000
Columns 365 through 371
23.6761 32.1277 24.0001 21.9790 51.1021 48.6596 51.0467
21.9000 27.5000 21.9000 23.1000 50.0000 50.0000 50.0000
Columns 372 through 378
38.7150 40.0930 11.7337 11.7271 19.3180 12.2218 14.0871
50.0000 50.0000 13.8000 13.8000 15.0000 13.9000 13.3000
Columns 379 through 385
10.6245 12.3102 11.2811 12.5886 12.6262 12.7699 8.7457
13.1000 10.2000 10.4000 10.9000 11.3000 12.3000 8.8000
Columns 386 through 392
8.8422 5.2698 8.0072 8.1700 14.5322 17.5716 16.0186
7.2000 10.5000 7.4000 10.2000 11.5000 15.1000 23.2000
Columns 393 through 399
9.8385 19.5303 15.8293 16.7939 16.1594 16.0031 5.2560
9.7000 13.8000 12.7000 13.1000 12.5000 8.5000 5.0000
Columns 400 through 406
11.0778 7.5946 12.6534 13.7895 7.5276 6.5614 4.2802
6.3000 5.6000 7.2000 12.1000 8.3000 8.5000 5.0000
Columns 407 through 413
13.7780 28.4038 16.2167 15.3346 16.2930 10.6613 11.2681
11.9000 27.9000 17.2000 27.5000 15.0000 17.2000 17.9000
Columns 414 through 420
15.1122 7.6163 7.5657 8.3258 10.5912 8.7514 10.9284
16.3000 7.0000 7.2000 7.5000 10.4000 8.8000 8.4000
Columns 421 through 427
16.8908 18.9752 21.6162 9.5188 12.4425 8.3453 14.5831
16.7000 14.2000 20.8000 13.4000 11.7000 8.3000 10.2000
Columns 428 through 434
9.2716 13.8301 9.5708 14.5073 11.7783 19.1158 16.5270
10.9000 11.0000 9.5000 14.5000 14.1000 16.1000 14.3000
Columns 435 through 441
14.5899 9.5630 11.7702 7.7339 5.5916 11.7561 6.6963
11.7000 13.4000 9.6000 8.7000 8.4000 12.8000 10.5000
Columns 442 through 448
12.4933 17.3840 12.9751 10.0512 9.2991 15.4655 14.4212
17.1000 18.4000 15.4000 10.8000 11.8000 14.9000 12.6000
Columns 449 through 455
13.2374 13.2950 11.7887 14.2879 15.7591 12.5250 10.9566
14.1000 13.0000 13.4000 15.2000 16.1000 17.8000 14.9000
Columns 456 through 462
13.5464 11.8807 12.4477 16.1538 16.4501 16.3458 18.2755
14.1000 12.7000 13.5000 14.9000 20.0000 16.4000 17.7000
Columns 463 through 469
17.0225 20.7452 18.1601 20.7623 12.4873 15.6683 15.4485
19.5000 20.2000 21.4000 19.9000 19.0000 19.1000 19.1000
Columns 470 through 476
19.0019 17.4639 22.5748 20.2223 22.6186 17.8242 13.9765
20.1000 19.9000 19.6000 23.2000 29.8000 13.8000 13.3000
Columns 477 through 483
16.1047 11.9184 16.2553 22.4462 23.2027 26.7181 26.4324
16.7000 12.0000 14.6000 21.4000 23.0000 23.7000 25.0000
Columns 484 through 490
21.5557 20.0931 20.0937 16.1954 23.1288 15.7670 12.6886
21.8000 20.6000 21.2000 19.1000 20.6000 15.2000 7.0000
Columns 491 through 497
8.1229 18.0084 20.7898 20.3537 22.0706 21.7872 19.0696
8.1000 13.6000 20.1000 21.8000 24.5000 23.1000 19.7000
Columns 498 through 504
19.4128 21.0991 18.7917 20.1158 22.0507 17.6495 24.3503
18.3000 21.2000 17.5000 16.8000 22.4000 20.6000 23.9000
Columns 505 through 506
22.1611 16.1823
22.0000 11.9000
<小时/>
您可以看到大多数样本匹配并且相对接近。然而,有些输出相差很远......所以此时真正需要调整神经网络,但不要调整太多,否则你会过度拟合数据。
查看文档以获取有关 sim
的更多详细信息:http://www.mathworks.com/help/nnet/ref/sim.html
关于matlab - 如何在 MATLAB 神经网络中输入新输入?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32743589/
我是一名优秀的程序员,十分优秀!