有没有大佬有里面这个ClassResult(train_sibie_labels, train_sibie, model, type)函数啊
%% 清空环境变量
close all;
clear;
clc;
format compact;
%% 数据提取
% 载入测试数据sibie,其中包含的数据为classnumber = 3,sibie:180*8的矩阵,wine_labes:180*1的列向量
load('yangben.txt');
load('sibie.txt');
load('sibie_labels.txt');
load('yangben_labels.txt');
classnumber=3;
%% 选定训练集和测试集
% 将第一类的1-10,第二类的41-50,第三类的81-90做为训练集
train_sibie = [yangben(1:20,:);yangben(21:40,:);yangben(41:60,:)];
% 相应的训练集的标签也要分离出来
train_sibie_labels = [yangben_labels(1:20);yangben_labels(21:40);yangben_labels(41:60)];
% 将第一类的11-40,第二类的51-80,第三类的91-120做为测试集
test_sibie = [sibie(1:80,:);sibie(81:160,:);sibie(161:240,:)];
% 相应的测试集的标签也要分离出来
test_sibie_labels = [sibie_labels(1:80);sibie_labels(81:160);sibie_labels(161:240)];
%% 数据预处理
% 数据预处理,将训练集和测试集归一化到[0,1]区间
[mtrain,ntrain] = size(train_sibie);
[mtest,ntest] = size(test_sibie);
dataset = [train_sibie;test_sibie];
% mapminmax为MATLAB自带的归一化函数
[dataset_scale,ps] = mapminmax(dataset',0,1);
dataset_scale = dataset_scale';
train_sibie = dataset_scale(1:mtrain,:);
test_sibie = dataset_scale( (mtrain+1):(mtrain+mtest),: );
%% SVM网络训练
model = svmtrain(train_sibie_labels, train_sibie, '-c 2 -w1 1.05 -g 1');
type = 1;
CR = ClassResult(train_sibie_labels, train_sibie, model, type);
%% SVM网络预测
[predict_label, accuracy,~] = svmpredict(test_sibie_labels, test_sibie, model);
type = 2;
CR = ClassResult(test_sibie_labels, test_sibie, model, type)
%% 结果分析
% 测试集的实际分类和预测分类图
figure;
hold on;
plot(test_sibie_labels,'o');
plot(predict_label,'r*');
xlabel('测试集样本','FontSize',12);
ylabel('类别标签','FontSize',12);
legend('实际测试集分类','预测测试集分类');
title('测试集的实际分类和预测分类图','FontSize',12);
grid on;
%% 清空环境变量
close all;
clear;
clc;
format compact;
%% 数据提取
% 载入测试数据sibie,其中包含的数据为classnumber = 3,sibie:180*8的矩阵,wine_labes:180*1的列向量
load('yangben.txt');
load('sibie.txt');
load('sibie_labels.txt');
load('yangben_labels.txt');
classnumber=3;
%% 选定训练集和测试集
% 将第一类的1-10,第二类的41-50,第三类的81-90做为训练集
train_sibie = [yangben(1:20,:);yangben(21:40,:);yangben(41:60,:)];
% 相应的训练集的标签也要分离出来
train_sibie_labels = [yangben_labels(1:20);yangben_labels(21:40);yangben_labels(41:60)];
% 将第一类的11-40,第二类的51-80,第三类的91-120做为测试集
test_sibie = [sibie(1:80,:);sibie(81:160,:);sibie(161:240,:)];
% 相应的测试集的标签也要分离出来
test_sibie_labels = [sibie_labels(1:80);sibie_labels(81:160);sibie_labels(161:240)];
%% 数据预处理
% 数据预处理,将训练集和测试集归一化到[0,1]区间
[mtrain,ntrain] = size(train_sibie);
[mtest,ntest] = size(test_sibie);
dataset = [train_sibie;test_sibie];
% mapminmax为MATLAB自带的归一化函数
[dataset_scale,ps] = mapminmax(dataset',0,1);
dataset_scale = dataset_scale';
train_sibie = dataset_scale(1:mtrain,:);
test_sibie = dataset_scale( (mtrain+1):(mtrain+mtest),: );
%% SVM网络训练
model = svmtrain(train_sibie_labels, train_sibie, '-c 2 -w1 1.05 -g 1');
type = 1;
CR = ClassResult(train_sibie_labels, train_sibie, model, type);
%% SVM网络预测
[predict_label, accuracy,~] = svmpredict(test_sibie_labels, test_sibie, model);
type = 2;
CR = ClassResult(test_sibie_labels, test_sibie, model, type)
%% 结果分析
% 测试集的实际分类和预测分类图
figure;
hold on;
plot(test_sibie_labels,'o');
plot(predict_label,'r*');
xlabel('测试集样本','FontSize',12);
ylabel('类别标签','FontSize',12);
legend('实际测试集分类','预测测试集分类');
title('测试集的实际分类和预测分类图','FontSize',12);
grid on;