基本信息
源码名称:BP神经网络分类
源码大小:3.13KB
文件格式:.zip
开发语言:MATLAB
更新时间:2019-09-23
友情提示:(无需注册或充值,赞助后即可获取资源下载链接)
嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):813200300
本次赞助数额为: 2 元×
微信扫码支付:2 元
×
请留下您的邮箱,我们将在2小时内将文件发到您的邮箱
源码介绍
clc; clear; load('irisdata.mat'); %读取训练数据 %[f1,f2,f3,f4,class] = textread('trainData.txt' , '%f%f%f%f%f',150); f1=[setosa(:,1);versicolour(:,1);virginica(:,1)]; f2=[setosa(:,2);versicolour(:,2);virginica(:,2)]; f3=[setosa(:,3);versicolour(:,3);virginica(:,3)]; f4=[setosa(:,4);versicolour(:,4);virginica(:,4)]; class=[ones(50,1);ones(50,1)*2;ones(50,1)*3]; %特征值归一化 [input,minI,maxI] = premnmx( [f1 , f2 , f3 , f4 ]') ; %构造输出矩阵 s = length( class) ; output = zeros( s , 3 ) ; for i = 1 : s output( i , class( i ) ) = 1 ; end %创建神经网络 net = newff( minmax(input) , [10 3] ); %, { 'logsig' 'purelin' } , 'traingdx' ) ; %设置训练参数 net.trainparam.show = 50 ; net.trainparam.epochs = 500 ; net.trainparam.goal = 0.01 ; net.trainParam.lr = 0.01 ; %开始训练 net = train( net, input , output' ) ; %读取测试数据 % [t1 t2 t3 t4 c] = textread('testData.txt' , '%f%f%f%f%f',150); t1=f1; t2=f2; t3=f3; t4=f4; c=class; %测试数据归一化 testInput = tramnmx ( [t1,t2,t3,t4]' , minI, maxI ) ; %仿真 Y = sim( net , testInput ) ; Y %统计识别正确率 [s1 , s2] = size( Y ) ; hitNum = 0 ; for i = 1 : s2 [m , Index] = max( Y( : , i ) ) ; if( Index == c(i) ) hitNum = hitNum 1 ; end end sprintf('识别率是 %3.3f%%',100 * hitNum / s2 )