一.任务要求
用SVM求解一个三类分类问题,实验数据为“鸢尾属植物数据集”,核函数为径向基核函数(RBF),误差评测标准为K折交叉确认误差。
二.实验方案
1. 用quadprog函数实现C-SVC来进行分类
——quadprog是matlab中一个求解二次规划的函数,通过适当的参数设置,可以利用quadprog函数实现C-SVC
2. 用matlab自带的SVM工具包来实现分类
——matlab2006版本中集成了SVM工具包,可以通过调用工具包中的svmtrain和svmclassify函数来进行训练和分类
3. 三类问题的分类方法
——将三类问题转化为三个两类问题,分别求出相应的决策函数即可(优点:方法简单易行;缺点:容易形成死区)
三.实验程序
1. 用Quadprog实现
clear all
%
Load the data and select features
for
classification
load fisheriris;
data
=
meas;
%
Get the size of the data
N
=
size(data,
1
);
%
Extract the Setosa
class
groups_temp
=
ismember(species,
'
versicolor
'
);
%
versicolor,virginica,setosa
%
convert the group to
1
&
-
1
groups
=
2
*
groups_temp
-
ones(N,
1
);
indices
=
crossvalind(
'
Kfold
'
, groups);
ErrorMin
=
1
;
for
r
=
1
:
1
:
5
for
C
=
1
:
1
:
5
ErrorNum
=
0
;
for
i
=
1
:
5
%
Use K
-
fold to
get
train data and test data
test
=
(indices
==
i); train
=
~
test;
traindata
=
data(train,:);
traingroup
=
groups(train,:);
trainlength
=
length(traingroup);

本文介绍了如何使用SVM(支持向量机)解决三类分类问题,以鸢尾花数据集为例,采用径向基核函数(RBF)。实验通过quadprog函数和MATLAB自带SVM工具包进行实现,并通过K折交叉验证评估误差。实验结果显示,不同类别和参数组合下,分类准确率在0.9430至1之间。
最低0.47元/天 解锁文章
1201

被折叠的 条评论
为什么被折叠?



