%% 清空环境变量
clc;
clear;
warning off
close all
%% 读取数据
res = xlsread('特征选择数据集.xlsx');
%% 清空环境变量
warning off % 关闭报警信息
close all % 关闭开启的图窗
clear % 清空变量
clc % 清空命令行
%% 导入数据
res = xlsread('特征选择数据集.xlsx');
%% 数据分析
num_size = 0.7; % 训练集占数据集比例
outdim = 1; % 最后一列为输出
num_samples = size(res, 1); % 样本个数
res = res(randperm(num_samples), :); % 打乱数据集(不希望打乱时,注释该行)
num_train_s = round(num_size * num_samples); % 训练集样本个数
f_ = size(res, 2) - outdim; % 输入特征维度
%% 划分训练集和测试集
P_train = res(1: num_train_s, 1: f_)';
T_train = res(1: num_train_s, f_ + 1: end)';
M = size(P_train, 2);
P_test = res(num_train_s + 1: end, 1: f_)';
T_test = res(num_train_s + 1: end, f_ + 1: end)';
N = size(P_test, 2);
%% 数据归一化
[p_train, ps_input] = mapminmax(P_train, 0, 1);
p_test = mapminmax('apply', P_test, ps_input);
[t_train, ps_output] = mapminmax(T_train, 0, 1);
t_test = mapminmax('apply', T_test, ps_output);
%% 特征选择
k = 9; % 保留特征个数
[save_index, mic] = mic_select(p_train, t_train, k);
%% 输出选择特征的对应序号
disp('经过特征选择后,保留特征的序号为:')
disp(save_index')
%% 特征重要性
figure
bar(mic)
xlabel('输入特征序号')
ylabel('最大互信息系数')
%% 特征选择后的数据集
p_train = p_train(save_index, :);
p_test = p_test (save_index, :);
%% 创建网络
net = newff(p_train, t_train, 9);
%% 设置训练参数
net.trainParam.epochs = 1000; % 迭代次数
net.trainParam.goal = 1e-6; % 误差阈值
net.trainParam.lr = 0.01; % 学习率
%% 训练网络
net = train(net, p_train, t_train);
%% 仿真测试
t_sim1 = sim(net, p_train);
t_sim2 = sim(net, p_test);
%% 数据反归一化
T_sim1 = mapminmax('reverse', t_sim1, ps_output);
T_sim2 = mapminmax('reverse', t_sim2, ps_output);
%% 均方根误差
error1 = sqrt(sum((T_sim1 - T_train).^2) ./ M);
error2 = sqrt(sum((T_sim2 - T_test ).^2) ./ N);
%%
%决定系数
R1 = 1 - norm(T_train - T_sim1)^2 / norm(T_train - mean(T_train))^2;
R2 = 1 - norm(T_test - T_sim2)^2 / norm(T_test - mean(T_test ))^2;
%%
%均方误差 MSE
mse1 = sum((T_sim1 - T_train).^2)./M;
mse2 = sum((T_sim2 - T_test).^2)./N;
%%
%RPD 剩余预测残差
SE1=std(T_sim1-T_train);
RPD1=std(T_train)/SE1;
SE=std(T_sim2-T_test);
RPD2=std(T_test)/SE;
%% 平均绝对误差MAE
MAE1 = mean(abs(T_train - T_sim1));
MAE2 = mean(abs(T_test - T_sim2));
%% 平均绝对百分比误差MAPE
MAPE1 = mean(abs((T_train - T_sim1)./T_train));
MAPE2 = mean(abs((T_test - T_sim2)./T_test));
%% 训练集绘图
figure
%plot(1:M,T_train,'r-*',1:M,T_sim1,'b-o','LineWidth',1)
plot(1:M,T_train,'-*',1:M,T_sim1,'-o','LineWidth',1.5)
legend('真实值','MIC-BP预测值')
xlabel('预测样本')
ylabel('预测结果')
string={'训练集预测结果对比';['(R^2 =' num2str(R1) ' RMSE= ' num2str(error1) ' MSE= ' num2str(mse1) ' RPD= ' num2str(RPD1) ')' ]};
title(string)
%% 预测集绘图
figure
plot(1:N,T_test,'-*',1:N,T_sim2,'-o','LineWidth',1.5)
legend('真实值','MIC-BP预测值')
xlabel('预测样本')
ylabel('预测结果')
string={'测试集预测结果对比';['(R^2 =' num2str(R2) ' RMSE= ' num2str(error2) ' MSE= ' num2str(mse2) ' RPD= ' num2str(RPD2) ')']};
title(string)
%% 测试集误差图
figure
ERROR3=T_test-T_sim2;
plot(T_test-T_sim2,'b-*','LineWidth',1.5)
xlabel('测试集样本编号')
ylabel('预测误差')
title('测试集预测误差')
grid on;
legend('MIC-BP预测输出误差')
%% 绘制线性拟合图
%% 训练集拟合效果图
figure
plot(T_train,T_sim1,'*r');
xlabel('真实值')
ylabel('预测值')
string = {'训练集效果图';['R^2_c=' num2str(R1) ' RMSEC=' num2str(error1) ]};
title(string)
hold on ;h=lsline;
set(h,'LineWidth',1,'LineStyle','-','Color',[1 0 1])
%% 预测集拟合效果图
figure
plot(T_test,T_sim2,'ob');
xlabel('真实值')
ylabel('预测值')
string1 = {'测试集效果图';['R^2_p=' num2str(R2) ' RMSEP=' num2str(error2) ]};
title(string1)
hold on ;h=lsline();
set(h,'LineWidth',1,'LineStyle','-','Color',[1 0 1])
%% 求平均
R3=(R1+R2)./2;
error3=(error1+error2)./2;
%% 总数据线性预测拟合图
tsim=[T_sim1,T_sim2]';
S=[T_train,T_test]';
figure
plot(S,tsim,'ob');
xlabel('真实值')
ylabel('预测值')
string1 = {'所有样本拟合预测图';['R^2_p=' num2str(R3) ' RMSEP=' num2str(error3) ]};
title(string1)
hold on ;h=lsline();
set(h,'LineWidth',1,'LineStyle','-','Color',[1 0 1])
%% 打印出评价指标
disp(['-----------------------误差计算--------------------------'])
disp(['评价结果如下所示:'])
disp(['平均绝对误差MAE为:',num2str(MAE2)])
disp(['均方误差MSE为: ',num2str(mse2)])
disp(['均方根误差RMSEP为: ',num2str(error2)])
disp(['决定系数R^2为: ',num2str(R2)])
disp(['剩余预测残差RPD为: ',num2str(RPD2)])
disp(['平均绝对百分比误差MAPE为: ',num2str(MAPE2)])
grid
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
Matlab实现基于MIC-BP最大互信息系数数据特征选择算法结合BP神经网络的数据回归预测(Matlab完整程序和数据) 1.最大互信息系数MIC(数据特征选择算法)的回归预测,MIC特征选择回归预测,多输入单输出模型。 2.多特征输入模型,直接替换数据就可以用。 3.语言为matlab。预测对比图,误差分析图,相关分析图。 4.运行环境matlab2018及以上。 经过特征选择后,保留特征的序号为: 152 153 154 155 156 157 158 159 160 -----------------------误差计算-------------------------- 评价结果如下所示: 平均绝对误差MAE为:0.27482 均方误差MSE为: 0.13341 均方根误差RMSEP为: 0.36525 决定系数R^2为: 0.94425 剩余预测残差RPD为: 4.2536 平均绝对百分比误差MAPE为: 0.0031803 >>
资源推荐
资源详情
资源评论
























收起资源包目录















共 13 条
- 1
资源评论


机器学习之心
- 粉丝: 5596
- 资源: 409
上传资源 快速赚钱
我的内容管理 展开
我的资源 快来上传第一个资源
我的收益
登录查看自己的收益我的积分 登录查看自己的积分
我的C币 登录后查看C币余额
我的收藏
我的下载
下载帮助


安全验证
文档复制为VIP权益,开通VIP直接复制
