這篇文章主要介紹“GRNN與PNN實(shí)例對比分析”,在日常操作中,相信很多人在GRNN與PNN實(shí)例對比分析問題上存在疑惑,小編查閱了各式資料,整理出簡單好用的操作方法,希望對大家解答”GRNN與PNN實(shí)例對比分析”的疑惑有所幫助!接下來,請跟著小編一起來學(xué)習(xí)吧!
郎溪網(wǎng)站建設(shè)公司成都創(chuàng)新互聯(lián),郎溪網(wǎng)站設(shè)計(jì)制作,有大型網(wǎng)站制作公司豐富經(jīng)驗(yàn)。已為郎溪上1000家提供企業(yè)網(wǎng)站建設(shè)服務(wù)。企業(yè)網(wǎng)站搭建\成都外貿(mào)網(wǎng)站制作要多少錢,請找那個售后服務(wù)好的郎溪做網(wǎng)站的公司定做!
%% 清空環(huán)境變量
clear
clc
%% 訓(xùn)練集/測試集產(chǎn)生
% 導(dǎo)入數(shù)據(jù)
load iris_data.mat
% 隨機(jī)產(chǎn)生訓(xùn)練集和測試集
P_train = [];
T_train = [];
P_test = [];
T_test = [];
for i = 1:3
temp_input = features((i-1)*50+1:i*50,:);
temp_output = classes((i-1)*50+1:i*50,:);
n = randperm(50);
% 訓(xùn)練集——120個樣本
P_train = [P_train temp_input(n(1:40),:)'];
T_train = [T_train temp_output(n(1:40),:)'];
% 測試集——30個樣本
P_test = [P_test temp_input(n(41:50),:)'];
T_test = [T_test temp_output(n(41:50),:)'];
end
%% 模型建立
result_grnn = [];
result_pnn = [];
time_grnn = [];
time_pnn = [];
for i = 1:4
for j = i:4
p_train = P_train(i:j,:);
p_test = P_test(i:j,:);
%% GRNN創(chuàng)建及仿真測試
t = cputime;
% 創(chuàng)建網(wǎng)絡(luò)
net_grnn = newgrnn(p_train,T_train);
% 仿真測試
t_sim_grnn = sim(net_grnn,p_test);
T_sim_grnn = round(t_sim_grnn);
t = cputime - t;
time_grnn = [time_grnn t];
result_grnn = [result_grnn T_sim_grnn'];
%% PNN創(chuàng)建及仿真測試
t = cputime;
Tc_train = ind2vec(T_train);
% 創(chuàng)建網(wǎng)絡(luò)
net_pnn = newpnn(p_train,Tc_train);
% 仿真測試
Tc_test = ind2vec(T_test);
t_sim_pnn = sim(net_pnn,p_test);
T_sim_pnn = vec2ind(t_sim_pnn);
t = cputime - t;
time_pnn = [time_pnn t];
result_pnn = [result_pnn T_sim_pnn'];
end
end
%% 性能評價
% 正確率accuracy
accuracy_grnn = [];
accuracy_pnn = [];
time = [];
for i = 1:10
accuracy_1 = length(find(result_grnn(:,i) == T_test'))/length(T_test);
accuracy_2 = length(find(result_pnn(:,i) == T_test'))/length(T_test);
accuracy_grnn = [accuracy_grnn accuracy_1];
accuracy_pnn = [accuracy_pnn accuracy_2];
end
% 結(jié)果對比
result = [T_test' result_grnn result_pnn];
accuracy = [accuracy_grnn;accuracy_pnn];
time = [time_grnn;time_pnn];
%% 繪圖
figure(1)
plot(1:30,T_test,'bo',1:30,result_grnn(:,4),'r-*',1:30,result_pnn(:,4),'k:^')
grid on
xlabel('測試集樣本編號')
ylabel('測試集樣本類別')
string = {'測試集預(yù)測結(jié)果對比(GRNN vs PNN)';['正確率:' num2str(accuracy_grnn(4)*100) '%(GRNN) vs ' num2str(accuracy_pnn(4)*100) '%(PNN)']};
title(string)
legend('真實(shí)值','GRNN預(yù)測值','PNN預(yù)測值')
figure(2)
plot(1:10,accuracy(1,:),'r-*',1:10,accuracy(2,:),'b:o')
grid on
xlabel('模型編號')
ylabel('測試集正確率')
title('10個模型的測試集正確率對比(GRNN vs PNN)')
legend('GRNN','PNN')
figure(3)
plot(1:10,time(1,:),'r-*',1:10,time(2,:),'b:o')
grid on
xlabel('模型編號')
ylabel('運(yùn)行時間(s)')
title('10個模型的運(yùn)行時間對比(GRNN vs PNN)')
legend('GRNN','PNN')
到此,關(guān)于“GRNN與PNN實(shí)例對比分析”的學(xué)習(xí)就結(jié)束了,希望能夠解決大家的疑惑。理論與實(shí)踐的搭配能更好的幫助大家學(xué)習(xí),快去試試吧!若想繼續(xù)學(xué)習(xí)更多相關(guān)知識,請繼續(xù)關(guān)注創(chuàng)新互聯(lián)網(wǎng)站,小編會繼續(xù)努力為大家?guī)砀鄬?shí)用的文章!