close all
clear all
clc
load x.txt;

load y.txt;

inputs = x';
targets = y;

% 创建一个模式识别网络(两层BP网络),同时给出中间层神经元的个数,这里使用20
hiddenLayerSize = 20;
net = patternnet(hiddenLayerSize);

% 对数据进行预处理,这里使用了归一化函数(一般不用修改)
% For a list of all processing functions type: help nnprocess
net.inputs{1}.processFcns = {'removeconstantrows','mapminmax'};
net.outputs{2}.processFcns = {'removeconstantrows','mapminmax'};

% 把训练数据分成三部分,训练网络、验证网络、测试网络
% For a list of all data division functions type: help nndivide
net.divideFcn = 'dividerand';  % Divide data randomly
net.divideMode = 'sample';  % Divide up every sample
net.divideParam.trainRatio = 70/100;
net.divideParam.valRatio = 15/100;
net.divideParam.testRatio = 15/100;

% 训练函数
% For a list of all training functions type: help nntrain
net.trainFcn = 'trainlm';  % Levenberg-Marquardt

% 使用均方误差来评估网络
% For a list of all performance functions type: help nnperformance
net.performFcn = 'mse';  % Mean squared error

% 画图函数
% For a list of all plot functions type: help nnplot
net.plotFcns = {'plotperform','plottrainstate','ploterrhist', ...
  'plotregression', 'plotfit'};

% 开始训练网络(包含了训练和验证的过程)
[net,tr] = train(net,inputs,targets);

% 测试网络
outputs = net(inputs);
errors = gsubtract(targets,outputs);
performance = perform(net,targets,outputs)

% 获得训练、验证和测试的结果
trainTargets = targets .* tr.trainMask{1};
valTargets = targets  .* tr.valMask{1};
testTargets = targets  .* tr.testMask{1};
trainPerformance = perform(net,trainTargets,outputs)
valPerformance = perform(net,valTargets,outputs)
testPerformance = perform(net,testTargets,outputs)

% 可以查看网络的各个参数
view(net)

% 根据画图的结果,决定是否满意
% Uncomment these lines to enable various plots.
figure, plotperform(tr)
figure, plottrainstate(tr)
figure, plotconfusion(targets,outputs)
figure, ploterrhist(errors)
% Test the Network
load z.txt;

testinputs= z';
testoutputs = net(testinputs);

最新文章

  1. Kafka replication
  2. 弹出popwindow 背景变暗
  3. MySQL数据类型和常用字段属性总结
  4. Asp.net Core 1.0.1升级到Asp.net Core 1.1.0 Preview版本发布到Windows Server2008 R2 IIS中的各种坑
  5. 总结隐藏Ribbon菜单的方法
  6. poj3687
  7. C加密解密
  8. 金山网络2014春季Android实习生招聘-成都站-笔试第二题
  9. 搭建LNMP架构
  10. 控件编写:增强 TMEMO (一)(增加对WM_HSCROLL消息的处理)
  11. Redis 持久化之RDB和AOP
  12. 我是如何确认线上CLOSE_WAIT产生的原因及如何解决的。
  13. 利用反射和JDBC元数据实现更加通用的查询方法
  14. [转]Cloudera Manager和CDH5.8离线安装
  15. [转]JDBC如何进行超时设置
  16. 【Android】Android EditText 去除边框
  17. js函数定义的三种方式
  18. free命令中buffers和caches的区别
  19. JavaScript:Number 对象
  20. 35个Jquery应用实例

热门文章

  1. MSSQL2008 中文乱码问题 (引自ljg888的专栏)
  2. SURF 特征法
  3. C#第十一天(winform)
  4. 最有用的Gulp插件汇总
  5. Hive 行列转换
  6. dpkg -P <pkg>
  7. 手动搭建SSI框架
  8. openstack添加数据库
  9. SQL Server 查看数据库是否存在阻塞
  10. linux卸载rpm包