如何在MATLAB神经网络中输入新输入?

时间:2015-09-23 15:24:32

标签: matlab machine-learning neural-network

我一直在研究神经网络,并试图利用MATLAB的神经网络工具箱和Mathworks提供的示例。到目前为止,我一直觉得这个主题非常有趣。

我对MATLAB代码有基本的了解。但是,我一直无法理解如何在训练后将自己的测试数据输入神经网络。一旦网络被训练,Mathworks中的示例似乎都会结束。

例如:http://in.mathworks.com/help/nnet/examples/wine-classification.html#zmw57dd0e324

在上面的链接中有一个“测试神经网络”部分,但没有提供有关正在使用的测试数据的信息。

我意识到这可能是一个新手问题,但我很感激任何理解这一点的帮助。

1 个答案:

答案 0 :(得分:1)

您使用神经网络工具箱中的sim命令。基本上,您需要提交M x N矩阵,其中M是要素总数,N是总样本数。 M与您拥有的输入层神经元的总数相关联。因此,对于每个输入,您都要在此矩阵中提供一列。

因此,一旦您训练网络并且如果您遵循该示例,您的神经网络应存储在net中。只需创建输入数据,并使用所需的输入“模拟”神经网络。

因此,您可以这样做,因为您的输入数据存储在X

Y = sim(net, X);

但是,如果您想查看神经网络如何使用相同的输入执行,请尝试使用变量x,因为输入数据存储在帖子中提到的数据集中的位置:

Y = sim(net, x);

或者,net是可以调用的对象。只需直接使用对象sim即可实现与net相同的功能:

Y = net(x);

如果您想进行小型测试,请尝试加载住房价格数据集:

[x,t] = house_dataset;

这将返回13个要素(行)的数据矩阵,共有506个样本。这存储在矩阵x中。向量t是输出层值,或者是通过神经网络运行后的目标值。您可以使用具有10个神经元的1个隐藏层的网络为该数据集训练神经网络,然后我们可以看到神经网络对相同输入数据的效果如何:

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

您可以看到大多数样本匹配且相对接近。然而,有些输出远远不够....所以它真的是关于此时调整神经网络,但不要调整过多,否则你会过度拟合数据。

查看文档,详细了解simhttp://www.mathworks.com/help/nnet/ref/sim.html