⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 masotti_mlp_classificazione.m

📁 多层感知器的分类程序!
💻 M
字号:
% Carico i dati in memoria: training e test set
% load banana_TRAINING; 
% load banana_TEST;
% load difficult_TRAINING.mat
% load difficult_TEST;
% load lithuanian_TRAINING.mat
% load lithuanian_TEST;
% load highleyman_TRAINING.mat
% load highleyman_TEST;
load spherical_TRAINING.mat
load spherical_TEST;



% Guardo come sono strutturati i dati che ho caricato
whos;



% Scalo le label: 1 diventa 0, 2 diventa 1
trl = trl - 1;
tel = tel - 1;



disp('Press any key to continue...'); pause;



% Grafico i dati del training set tr
figure;
plot(tr(find(trl==0),1),tr(find(trl==0),2),'ro'); hold on;
plot(tr(find(trl==1),1),tr(find(trl==1),2),'b*'); hold on;
axis([-12 8 -12 8]);
title('Training set');
hold off;



disp('Press any key to continue...'); pause;



% Grafico i dati del test set te
figure;
plot(te(find(tel==0),1),te(find(tel==0),2),'ro'); hold on;
plot(te(find(tel==1),1),te(find(tel==1),2),'b*'); hold on;
axis([-12 8 -12 8]);
title('Test set');
hold off;



disp('Press any key to continue...'); pause;



% Creo una architettura a piacere per la rete neurale
nin = 2;
nhidden = 10;
nout = 1;
alpha = 0.2;	% Weight decay
ncycles = 100;	% Number of training cycles: provare 10:10:100
net = mlp(nin, nhidden, nout, 'logistic', alpha); % Set up MLP network
net % Visualizzo l'architettura della rete neurale
%net.w1 % Visualizzo i pesi tra lo strato di Input e quello Hidden
%net.w2 % Visualizzo i pesi tra lo strato Hidden e quello di Output



disp('Press any key to continue...'); pause;



% Addestro la rete neurale
options = zeros(1,18);
options(1) = 1;                 % Print out error values
options(14) = ncycles;
net = netopt(net, options, tr, trl, 'quasinew'); % Train using quasi-Newton.
net % Visualizzo l'architettura della rete neurale dopo l'addestramento
%net.w1 % Visualizzo i pesi tra lo strato di Input e quello Hidden dopo l'addestramento
%net.w2 % Visualizzo i pesi tra lo strato Hidden e quello di Output dopo l'addestramento



disp('Press any key to continue...'); pause;



% Testo la rete neurale sul training set tr
y = mlpfwd(net, tr);
[ConfusionMatrix ClassificationRate] = confmat(y,trl) % y-axis = actual class, x-axis = predicted class



disp('Press any key to continue...'); pause;



% Grafico la curva trovata dalla rete neurale sul training set tr: attenzione, e' solo una questione di GRAFICA
x0 = min(tr(:,1));
x1 = max(tr(:,1));
y0 = min(tr(:,2));
y1 = max(tr(:,2));
xrange = [x0:x1];
yrange = [y0:y1];
[X Y] = meshgrid([x0:x1],[y0:y1]);
yg = mlpfwd(net, [X(:) Y(:)]);
yg = reshape(yg(:,1),size(X));
figure;
contour(xrange,yrange,yg,[0.5 0.5]); hold on; 
plot(tr(find(trl==0),1),tr(find(trl==0),2),'ro'); hold on;
plot(tr(find(trl==1),1),tr(find(trl==1),2),'b*');
axis([-12 8 -12 8]);
title('Rete neurale testata sul training set');
hold off;



disp('Press any key to continue...'); pause;



% Testo la rete neurale sul test set te
yt = mlpfwd(net, te);
[ConfusionMatrix ClassificationRate] = confmat(yt,tel) % y-axis = actual class, x-axis = predicted class



disp('Press any key to continue...'); pause;



% Grafico la curva trovata dalla rete neurale sul test set te: attenzione, e' solo una questione di GRAFICA
x0 = min(tr(:,1));
x1 = max(tr(:,1));
y0 = min(tr(:,2));
y1 = max(tr(:,2));
xrange = [x0:x1];
yrange = [y0:y1];
[X Y] = meshgrid([x0:x1],[y0:y1]);
yg = mlpfwd(net, [X(:) Y(:)]);
yg = reshape(yg(:,1),size(X));
figure;
contour(xrange,yrange,yg,[0.5 0.5]); hold on;
plot(te(find(tel==0),1),te(find(tel==0),2),'ro'); hold on;
plot(te(find(tel==1),1),te(find(tel==1),2),'b*'); 
axis([-12 8 -12 8]);
title('Rete neurale testata sul test set');
hold off;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -