%% 清空环境变量
warning off % 关闭报警信息
close all % 关闭开启的图窗
clear % 清空变量
clc % 清空命令行
tic
% restoredefaultpath
%% 读取数据
res = xlsread('数据集.xlsx');
%% 划分训练集和测试集%
P_train = res(1: 250, 1: 12)';
T_train = res(1: 250, 13)';
M = size(P_train, 2);
P_test = res(251: end, 1: 12)';
T_test = res(251: end, 13)';
N = size(P_test, 2);
num_dim = size(P_train, 1); % 特征维度
num_class = length(unique(res(:, end))); % 类别数(Excel最后一列放类别) % 类别数(Excel最后一列放类别)
%% 数据转置
% P_train = P_train'; P_test = P_test';
% T_train = T_train'; T_test = T_test';
%% 得到训练集和测试样本个数
M = size(P_train, 2);
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 )';
%% 格式转换
for i = 1 : M
p_train{i, 1} = P_train(:, i);
end
for i = 1 : N
p_test{i, 1} = P_test(:, i);
end
智能算法及其模型预测
标签:end,预测,%%,res,分类,RMBO,train,test,size From: https://blog.csdn.net/qq_43916303/article/details/143809350