%*****************************************************************************************************************************************************************************************************************
%% 清空环境变量
warning off % 关闭报警信息
close all % 关闭开启的图窗
clear % 清空变量
clc % 清空命令行
%*****************************************************************************************************************************************************************************************************************
%% 导入数据
res = xlsread(‘data.xlsx’);
%% 划分训练集和测试集
temp = randperm(357);
%*****************************************************************************************************************************************************************************************************************
P_train = res(temp(1: 240), 1: 12)‘;
T_train = res(temp(1: 240), 13)’;
M = size(P_train, 2);
%*****************************************************************************************************************************************************************************************************************
P_test = res(temp(241: end), 1: 12)‘;
T_test = res(temp(241: end), 13)’;
N = size(P_test, 2);
%% 数据归一化
[P_train, ps_input] = mapminmax(P_train, 0, 1);
P_test = mapminmax(‘apply’, P_test, ps_input);
t_train = categorical(T_train)‘;
t_test = categorical(T_test )’;
%*****************************************************************************************************************************************************************************************************************
%*********************************************************************************************************************************************************************
%% 仿真预测
t_sim1 = predict(net, p_train);
t_sim2 = predict(net, p_test );
%*****************************************************************************************************************************************************************************************************************
%% 数据反归一化
T_sim1 = vec2ind(t_sim1’);
T_sim2 = vec2ind(t_sim2’);
%% 性能评价
error1 = sum((T_sim1 == T_train)) / M * 100 ;
error2 = sum((T_sim2 == T_test )) / N * 100 ;
%% 查看网络结构
analyzeNetwork(net)
%*****************************************************************************************************************************************************************************************************************
%% 数据排序
[T_train, index_1] = sort(T_train);
[T_test , index_2] = sort(T_test );
T_sim1 = T_sim1(index_1);
T_sim2 = T_sim2(index_2);
%*****************************************************************************************************************************************************************************************************************
%% 绘图
figure
plot(1: M, T_train, ‘r-', 1: M, T_sim1, ‘b-o’, ‘LineWidth’, 1)
legend(‘真实值’, ‘预测值’)
xlabel(‘预测样本’)
ylabel(‘预测结果’)
string = {‘训练集预测结果对比’; [‘准确率=’ num2str(error1) ‘%’]};
title(string)
xlim([1, M])
grid
%*****************************************************************************************************************************************************************************************************************
figure
plot(1: N, T_test, 'r-’, 1: N, T_sim2, ‘b-o’, ‘LineWidth’, 1)
legend(‘真实值’, ‘预测值’)
xlabel(‘预测样本’)
ylabel(‘预测结果’)
string = {‘测试集预测结果对比’; [‘准确率=’ num2str(error2) ‘%’]};
title(string)
xlim([1, N])
grid
%% 混淆矩阵
figure
cm = confusionchart(T_train, T_sim1);
cm.Title = ‘Confusion Matrix for Train Data’;
cm.ColumnSummary = ‘column-normalized’;
cm.RowSummary = ‘row-normalized’;
%*****************************************************************************************************************************************************************************************************************
figure
cm = confusionchart(T_test, T_sim2);
cm.Title = ‘Confusion Matrix for Test Data’;
cm.ColumnSummary = ‘column-normaliz
————————————————
————————————————
版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
原文链接:https://blog.csdn.net/m0_57362105/article/details/143661815
标签:sim2,sim1,cm,%%,Att,train,多特,test,门控 From: https://blog.csdn.net/m0_57362105/article/details/143661860