matlab 神经网络 ANN 分类
Posted studyer_domi
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了matlab 神经网络 ANN 分类相关的知识,希望对你有一定的参考价值。
1、内容简介
略
500-可以交流、咨询、答疑
2、内容说明
clear
clc
close all
%% import and deal data
filename = "DAY 1-DAY28 AVERAGE DATA SETS----A.B.C -split by 28 × 6 classification.xlsx";
datatrain = xlsread(filename, "Sheet1");
datatest = xlsread(filename, "Sheet2");
datavalidation = xlsread(filename, "Sheet3");
Xtrain = datatrain(:,1:4)';
% Xtrain(2,:) = 100*Xtrain(2,:);
Ytrain = datatrain(:,5)';
[~,nber] = size(Xtrain);
order = randperm(nber);
XTrain1 = Xtrain(:,order);
YTrain1 = Ytrain(:,order);
XValidation = datavalidation(:,1:4)';
% XValidation(2,:) = 100*XValidation(2,:);
YValidation = datavalidation(:,5)';
[~,nber] = size(XValidation);
order = randperm(nber);
XValidation1 = XValidation(:,order);
YValidation1 = YValidation(:,order);
Xtest = datatest(:,1:4)';
% Xtest(2,:) = 100*Xtest(2,:);
Ytest = datatest(:,5)';
[~,nber] = size(Xtest);
order = randperm(nber);
Xtest1 = Xtest(:,order);
Ytest1 = Ytest(:,order);
XTrain = [XTrain1 XValidation1 Xtest1];
YTrain = [YTrain1 YValidation1 Ytest1];
% [p1,minp,maxp,t1,mint,maxt]=premnmx(XTrain,YTrain);
% load net.mat
% accuary(net, XTrain, YTrain, minp, maxp, mint,maxt)
% accuary(net, XValidation, YValidation, minp, maxp, mint,maxt)
% accuary(net, Xtest, Ytest, minp, maxp, mint,maxt)
%% 训练
%数据做归一化
% [p1,minp,maxp,t1,mint,maxt]=premnmx(XTrain,output');
[p1,minp,maxp,t1,mint,maxt]=premnmx(XTrain,YTrain);
%创建网络
% logsig:对数S形转移函数,单极性;tansig: 双极性S形转移函数;purelin:线性函数
% traingdx :梯度下降自适应学习率训练函数,traingdm,trainlm, trainscg 这些是权值的学习算法
% traingdm是带动量的梯度下降法,trainlm是指L-M优化算法,trainscg是指量化共轭梯度法
% 网络结构:三个隐含层、且神经元数分别为5、12的前向BP网络,1个output
% net=newff(minmax(p1),[6, 15, 1],'tansig', 'tansig','purelin','trainlm');
net=newff(minmax(p1),[12, 24, 32, 24, 1],'tansig', 'tansig', 'tansig', 'tansig', 'purelin','trainlm');
% net=newff(minmax(p1),[5, 12, 3],'tansig', 'tansig','purelin','trainlm');
%设置训练次数
net.trainParam.epochs = 600;
%设置收敛误差
net.trainParam.goal=0.0001;
%设置学习率
net.trainParam.lr = 0.03 ;
%设置动量因子,避免局部最优和过拟合
net.trainParam.mc=0.9;
%最小确认失败次数
net.trainParam.max_fail=30;
%训练网络
[net,tr]=train(net,p1,t1);
%%
fuse_matrix_train = accuary(net, XTrain, YTrain, minp, maxp, mint,maxt);
fuse_matrix_Validation = accuary(net, XValidation, YValidation, minp, maxp, mint,maxt);
fuse_matrix_test = accuary(net, Xtest, Ytest, minp, maxp, mint,maxt);
%%
figure
imagesc(fuse_matrix_train)
set(gca,'xtick',1:3)
set(gca,'xticklabel','1 ','2','3','XTickLabelRotation',45)
set(gca,'ytick',1:3)
set(gca,'yticklabel','1 ','2','3')
set(gca,'FontSize',14,'Fontname', 'Times New Roman');
colorbar
title ("train data")
xlabel('truth')
ylabel("predict")
[m,n] = size(fuse_matrix_train);
for i = 1:m
for j = 1:n
x = i;
y = j;
text(x,y,num2str(fuse_matrix_train(i,j)))
end
end
%
figure
imagesc(fuse_matrix_Validation)
set(gca,'xtick',1:3)
set(gca,'xticklabel','1 ','2','3','XTickLabelRotation',45)
set(gca,'ytick',1:3)
set(gca,'yticklabel','1 ','2','3')
set(gca,'FontSize',14,'Fontname', 'Times New Roman');
colorbar
title ("Validation data")
xlabel('truth')
ylabel("predict")
[m,n] = size(fuse_matrix_Validation);
for i = 1:m
for j = 1:n
x = i;
y = j;
text(x,y,num2str(fuse_matrix_Validation(i,j)))
end
end
%
figure
imagesc(fuse_matrix_test)
set(gca,'xtick',1:3)
set(gca,'xticklabel','1 ','2','3','XTickLabelRotation',45)
set(gca,'ytick',1:3)
set(gca,'yticklabel','1 ','2','3')
set(gca,'FontSize',14,'Fontname', 'Times New Roman');
colorbar
title ("test data")
xlabel('truth')
ylabel("predict")
[m,n] = size(fuse_matrix_test);
for i = 1:m
for j = 1:n
x = i;
y = j;
text(x,y,num2str(fuse_matrix_test(i,j)))
end
end
3、仿真分析
4、参考论文
略
以上是关于matlab 神经网络 ANN 分类的主要内容,如果未能解决你的问题,请参考以下文章