MatlabSVM工具箱快速入手简易教程.doc

上传人:wj 文档编号:2111716 上传时间:2023-05-02 格式:DOC 页数:9 大小:141.50KB
下载 相关 举报
MatlabSVM工具箱快速入手简易教程.doc_第1页
第1页 / 共9页
MatlabSVM工具箱快速入手简易教程.doc_第2页
第2页 / 共9页
MatlabSVM工具箱快速入手简易教程.doc_第3页
第3页 / 共9页
MatlabSVM工具箱快速入手简易教程.doc_第4页
第4页 / 共9页
MatlabSVM工具箱快速入手简易教程.doc_第5页
第5页 / 共9页
MatlabSVM工具箱快速入手简易教程.doc_第6页
第6页 / 共9页
MatlabSVM工具箱快速入手简易教程.doc_第7页
第7页 / 共9页
MatlabSVM工具箱快速入手简易教程.doc_第8页
第8页 / 共9页
MatlabSVM工具箱快速入手简易教程.doc_第9页
第9页 / 共9页
亲,该文档总共9页,全部预览完了,如果喜欢就下载吧!
下载资源
资源描述

MatlabSVM工具箱快速入手简易教程.doc

《MatlabSVM工具箱快速入手简易教程.doc》由会员分享,可在线阅读,更多相关《MatlabSVM工具箱快速入手简易教程.doc(9页珍藏版)》请在冰点文库上搜索。

MatlabSVM工具箱快速入手简易教程.doc

SVM工具箱快速入手简易教程(byfaruto)

一.matlab自带的函数(matlab帮助文件里的例子)[只有较新版本的matlab中有这两个SVM的函数]

=====

svmtrainsvmclassify

=====简要语法规则====

svmtrain

Trainsupportvectormachineclassifier

Syntax

SVMStruct=svmtrain(Training,Group)

SVMStruct=svmtrain(...,'Kernel_Function',Kernel_FunctionValue,...)

SVMStruct=svmtrain(...,'RBF_Sigma',RBFSigmaValue,...)

SVMStruct=svmtrain(...,'Polyorder',PolyorderValue,...)

SVMStruct=svmtrain(...,'Mlp_Params',Mlp_ParamsValue,...)

SVMStruct=svmtrain(...,'Method',MethodValue,...)

SVMStruct=svmtrain(...,'QuadProg_Opts',QuadProg_OptsValue,...)

SVMStruct=svmtrain(...,'SMO_Opts',SMO_OptsValue,...)

SVMStruct=svmtrain(...,'BoxConstraint',BoxConstraintValue,...)

SVMStruct=svmtrain(...,'Autoscale',AutoscaleValue,...)

SVMStruct=svmtrain(...,'Showplot',ShowplotValue,...)

---------------------

svmclassify

Classifydatausingsupportvectormachine

Syntax

Group=svmclassify(SVMStruct,Sample)

Group=svmclassify(SVMStruct,Sample,'Showplot',ShowplotValue)

============================实例研究====================

loadfisheriris

%载入matlab自带的数据[有关数据的信息可以自己到UCI查找,这是UCI的经典数据之一],得到的数据如下图:

tu1

1.jpg(7.94KB)

2009-5-1219:

50

其中meas是150*4的矩阵代表着有150个样本每个样本有4个属性描述,species代表着这150个样本的分类.

data=[meas(:

1),meas(:

2)];

%在这里只取meas的第一列和第二列,即只选取前两个属性.

groups=ismember(species,'setosa');

%由于species分类中是有三个分类:

setosa,versicolor,virginica,为了使问题简单,我们将其变为二分类问题:

Setosaandnon-Setosa.

[train,test]=crossvalind('holdOut',groups);

cp=classperf(groups);

%随机选择训练集合测试集[有关crossvalind的使用请自己help一下]

其中cp作用是后来用来评价分类器的.

svmStruct=svmtrain(data(train,:

),groups(train),'showplot',true);

%使用svmtrain进行训练,得到训练后的结构svmStruct,在预测时使用.

训练结果如图:

tu2

2.jpg(26.86KB)

2009-5-1219:

50

classes=svmclassify(svmStruct,data(test,:

),'showplot',true);

%对于未知的测试集进行分类预测,结果如图:

tu3

3.jpg(37.34KB)

2009-5-1219:

50

classperf(cp,classes,test);

cp.CorrectRate

ans=

  0.9867

%分类器效果测评,就是看测试集分类的准确率的高低.

二.台湾林智仁的libsvm工具箱

该工具箱下载[libsvm-mat-2.86-1]:

libsvm-mat-2.86-1.rar(73.75KB)

libsvm-mat-2.86-1.rar(73.75KB)

下载次数:

373

2009-5-1220:

02

安装方法也很简单,解压文件,把当前工作目录调整到libsvm所在的文件夹下,再在setpath里将libsvm所在的文件夹加到里面.然后

在命令行里输入

mex-setup  %选择一下编译器

make

这样就可以了.

建议大家使用libsvm工具箱,这个更好用一些.可以进行分类[多类别],预测....

=========

svmtrain

svmpredict

================

简要语法:

Usage

=====

matlab>model=svmtrain(training_label_vector,training_instance_matrix[,'libsvm_options']);

      -training_label_vector:

        Anmby1vectoroftraininglabels(typemustbedouble).

      -training_instance_matrix:

        Anmbynmatrixofmtraininginstanceswithnfeatures.

        Itcanbedenseorsparse(typemustbedouble).

      -libsvm_options:

        AstringoftrainingoptionsinthesameformatasthatofLIBSVM.

matlab>[predicted_label,accuracy,decision_values/prob_estimates]=svmpredict(testing_label_vector,testing_instance_matrix,model[,'libsvm_options']);

      -testing_label_vector:

        Anmby1vectorofpredictionlabels.Iflabelsoftest

        dataareunknown,simplyuseanyrandomvalues.(typemustbedouble)

      -testing_instance_matrix:

        Anmbynmatrixofmtestinginstanceswithnfeatures.

        Itcanbedenseorsparse.(typemustbedouble)

      -model:

        Theoutputofsvmtrain.

      -libsvm_options:

        AstringoftestingoptionsinthesameformatasthatofLIBSVM.

ReturnedModelStructure

========================

实例研究:

loadheart_scale.mat

%工具箱里自带的数据

如图:

tu4

4.jpg(9.36KB)

2009-5-1220:

08

其中heart_scale_inst是样本,heart_scale_label是样本标签

model=svmtrain(heart_scale_label,heart_scale_inst,'-c1-g0.07');

%训练样本,具体参数的调整请看帮助文件

[predict_label,accuracy,dec_values]=svmpredict(heart_scale_label,heart_scale_inst,model);

%分类预测,这里把训练集当作测试集,验证效果如下:

>>[predict_label,accuracy,dec_values]=svmpredict(heart_scale_label,heart_scale_inst,model);%testthetrainingdata

Accuracy=86.6667%(234/270)(classification)

==============

这回把SVM这点入门的东西都说完了,大家可以参照着上手了,有关SVM的原理我下面有个简易的PPT,是以前做项目时我做的[当时我负责有关SVM这一块代码实现讲解什么的],感兴趣的你可以看看,都是上手较快的东西,想要深入学习SVM,你的学习统计学习理论什么的....挺多的呢..

SVM.ppt(391KB)

SVM.ppt(391KB)

下载次数:

429

2009-5-1220:

18

-----------有关SVM和libsvm的非常好的资料,想要详细研究SVM看这个------

libsvm_guide.pdf(194.53KB)

libsvm_guide.pdf(194.53KB)

下载次数:

186

2009-8-1914:

58

libsvm_library.pdf(316.82KB)

libsvm_library.pdf(316.82KB)

下载次数:

137

2009-8-1914:

58

OptimizationSupportVectorMachinesandMachine

展开阅读全文
相关资源
猜你喜欢
相关搜索
资源标签

当前位置:首页 > PPT模板 > 商务科技

copyright@ 2008-2023 冰点文库 网站版权所有

经营许可证编号:鄂ICP备19020893号-2