%% 清空环境变量
warning off % 关闭报警信息
close all % 关闭开启的图窗
clear % 清空变量
clc % 清空命令行
res = xlsread('数据集.xlsx');
%%
num_size = 0.8;% 训练集占数据集比例
dataran = 0; %不打乱数据
%%
%% 数据分析
outdim = 1; % 最后一列为输出
num_samples = size(res, 1); % 样本个数
num_train_s = round(num_size * num_samples); % 训练集样本个数
AA1 = res(1:num_train_s,:);
AA2 = res(num_train_s+1:end-1,:);
AA3 = res(end,:);
clear res;
if dataran == 1
AA1 = AA1(randperm(size(AA1, 1)), :); % 打乱数据集
AA2 = AA2(randperm(size(AA2, 1)), :); % 打乱数据集
end
res=[AA1;AA2;AA3];
f_ = size(res, 2) - outdim; % 输入特征维度
%% 划分训练集和测试集
P_train = res(1: num_train_s, 1: f_)';
T_train = res(1: num_train_s, end)';
M = size(P_train, 2);
P_test = res(num_train_s + 1: end, 1: f_)';
T_test = res(num_train_s + 1: end, 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);
%% 创建元胞或向量,长度为训练集大小;
XrTrain = cell(size(p_train,2),1);
YrTrain = zeros(size(t_train,2),1);
for i=1:size(p_train,2)
XrTrain{i,1} = p_train(:,i);
YrTrain(i,1) = t_train(:,i);
end
智能算法及其模型预测