• 大小: 2KB
    文件类型: .rar
    金币: 1
    下载: 0 次
    发布日期: 2021-06-18
  • 语言: Matlab
  • 标签: BP算法  

资源简介

MATLAB平台下实现构造前馈神经网络,实现BP算法,对鸢尾花数据集进行分类。

资源截图

代码片段和文件信息

%读取训练数据
[f1f2f3f4class] = textread(‘trainData.txt‘  ‘%f%f%f%f%f‘150);

%特征值归一化
[inputminImaxI] = 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 = 3000;
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);

%测试数据归一化
testInput = tramnmx ( [t1t2t3t4]‘  minI maxI ) ;

%仿真
Y = sim( net  testInput ) 

%统计识别正确率
[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 )


 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件        997  2018-05-14 12:50  bpAnnIris.m

     文件       1349  2011-07-10 13:38  testData.txt

     文件       2708  2011-07-10 13:42  totalData.txt

     文件       1359  2011-07-10 13:39  trainData.txt

----------- ---------  ---------- -----  ----

                 6413                    4


评论

共有 条评论