%% SVM分类预测----炉温趋势种类识别
%% 清空环境变量
close all;
clear;
clc;
format compact;
%% 数据提取
% 载入测试数据
% 类别标签classnumber = 3,样本输入two:90*5的矩阵(风量、当前炉与上一炉风量差值、热风压力差值、压差差值、透气性差值),样本的类别输出label:90*1的列向量
load classnumber.mat;
load label.mat;
load two.mat;
% 画出测试数据的分维可视化图
figure
subplot(3,2,1);
hold on
for run = 1:90
plot(run,label(run),'*');
end
xlabel('样本','FontSize',10);
ylabel('类别标签','FontSize',10);
title('class','FontSize',10);
for run = 2:6
subplot(3,2,run);
hold on;
str = ['attrib ',num2str(run-1)];
for i = 1:90
plot(i,two(i,run-1),'*');
end
xlabel('样本','FontSize',10);
ylabel('属性值','FontSize',10);
title(str,'FontSize',10);
end
% 选定训练集和测试集
% 将第一类的1-10,第二类的31-40,第三类的61-70做为训练集
train_temper = [two(1:10,:);two(31:40,:);two(61:70,:)];
% 相应的训练集的标签也要分离出来
train_temper_label = [label(1:10,:);label(31:40,:);label(61:70,:)];
% 将第一类的11-30,第二类的41-60,第三类的71-90做为测试集
test_temper = [two(11:30,:);two(41:60,:);two(71:90,:)];
% 相应的测试集的标签也要分离出来
test_temper_label = [label(11:30,:);label(41:60,:);label(71:90,:)];
%% 数据预处理
% 数据预处理,将训练集和测试集归一化到[0,1]区间
[mtrain,ntrain] = size(train_temper);
[mtest,ntest] = size(test_temper);
dataset = [train_temper;test_temper];
% mapminmax为MATLAB自带的归一化函数
[dataset_scale,ps] = mapminmax(dataset',0,1);
dataset_scale = dataset_scale';
train_temper = dataset_scale(1:mtrain,:);
test_temper = dataset_scale( (mtrain+1):(mtrain+mtest),: );
%% SVM网络训练
model = svmtrain(train_temper_label, train_temper, '-s 0 -t 0 -c 2 -g 1');
%% SVM网络预测
[predict_label, accuracy] = svmpredict(test_temper_label, test_temper, model);
%% 结果分析
% 测试集的实际分类和预测分类图
figure;
hold on;
plot(test_temper_label,'o');
plot(predict_label,'r*');
xlabel('测试样本集','FontSize',12);
ylabel('类别标签','FontSize',12);
legend('样本实际分类','样本预测分类');
grid on;