BP神經網路與MATLAB實現案例一

2021-08-07 09:35:07 字數 1454 閱讀 6009

眾做周知,bp神經網路是最常用的一種神經網路。

本文主要講解%實現對玫瑰的識別%案例。

關於神經網路的介紹與bp的詳解,論壇裡鋪天蓋地,不在此贅述。

簡要概括一下:

歸一化資料、構造輸出矩陣、建立神經網路、設定引數、啟動訓練、反歸一化、**

其中最大迭代次數300、期望誤差0.01、學習效率0.01

輸出識別率:96.00%

迭代150次之後時基本穩定,結果很可觀

clc

clear

%讀取資料

[f1,f2,f3,f4,class] = textread('rose.txt' , '%f%f%f%f%f',150);

%歸一化

[input,mini,maxi] = premnmx( [f1 , f2 , f3 , f4 ]') ;

s = length( class ) ;

output = zeros( s , 3 ) ;

fori = 1 : s

output( i , class( i ) ) = 1 ;

end%建立網路

net = newff( minmax(input) , [10

3] , , 'traingdx' ) ;

%設定訓練引數

net.

trainparam.show = 50 ;

net.

trainparam.epochs = 300;

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 ( [t1,t2,t3,t4]' , mini, maxi ) ;

y = sim( net , testinput )

[s1 , s2] = size( y ) ;

hitnum = 0 ;

fori = 1 : s2

[m , index] = max( y( : , i ) ) ;

if( index == c(i) )

hitnum = hitnum + 1 ;

endendsprintf('識別率是 %3.3f%%',100 * hitnum / s2 )

Matlab實現BP神經網路

該實現為 資料探勘 課程的一次作業。資料在 上,所以資料為csv格式。但bp神經網路演算法為最一般的實現,所以有參考價值。close all 關閉開啟的檔案 clear 清除記憶體中的資料 echo on 顯示執行的每一條命令 clc 清除命令列視窗 pause 敲任意鍵開始 定義訓練樣本 p為輸入...

BP神經網路與MATLAB實現案例二

你現在手裡有一袋子雞腿 j 一袋子葡萄 t 要去換人家的西瓜 h 假設雞腿20元 斤,葡萄17元 斤,西瓜2元 斤 也就是h 20j 17t 2 當然我們要通過機器去實現它 給出一組資料 讓我們對她進行一系列的 化 input,ps1 mapminmax j t target,ps2 mapminm...

BP神經網路(基於MATLAB)

clc clear all 匯入資料 load s data.mat s含量所用資料 n 12 n 是自變數的個數 m 1 m 是因變數的個數 讀取訓練資料 train num 1600 訓練樣本數 train data s data 1 train num,特徵值歸一化 train input,m...