支持向量机matlab实例及理论-20131201

整理文档很辛苦,赏杯茶钱您下走!

免费阅读已结束,点击下载阅读编辑剩下 ...

阅读已结束,您可以下载文档离线阅读编辑

资源描述

支持向量机matlab分类实例及理论线性支持向量机可对线性可分的样本群进行分类,此时不需要借助于核函数就可较为理想地解决问题。非线性支持向量机将低维的非线性分类问题转化为高维的线性分类问题,然后采用线性支持向量机的求解方法求解。此时需要借助于核函数,避免线性分类问题转化为非线性分类问题时出现的维数爆炸难题,从而避免由于维数太多而无法进行求解。第O层:Matlab的SVM函数求解分类问题实例0.1Linearclassification%TwoDimensionLinear-SVMProblem,TwoClassandSeparableSituation%MethodfromChristopherJ.C.Burges:%ATutorialonSupportVectorMachinesforPatternRecognition,page9%Optimizing||W||directly:%Objective:minf(A)=||W||,p8/line26%Subjectto:yi*(xi*W+b)-1=0,function(12);clearall;closeallclc;sp=[3,7;6,6;4,6;5,6.5]%positivesamplepointsnsp=size(sp);sn=[1,2;3,5;7,3;3,4;6,2.7]%negativesamplepointsnsn=size(sn)sd=[sp;sn]lsd=[truetruetruetruefalsefalsefalsefalsefalse]Y=nominal(lsd)figure(1);subplot(1,2,1)plot(sp(1:nsp,1),sp(1:nsp,2),'m+');holdonplot(sn(1:nsn,1),sn(1:nsn,2),'c*');subplot(1,2,2)svmStruct=svmtrain(sd,Y,'showplot',true);0.2NonLinearclassificationclearall;closeallclc;sp=[3,7;6,6;4,6;5,6.5]%positivesamplepointsnsp=size(sp);sn=[1,2;3,5;7,3;3,4;6,2.7;4,3;2,7]%negativesamplepointsnsn=size(sn)sd=[sp;sn]lsd=[truetruetruetruefalsefalsefalsefalsefalsefalsefalse]Y=nominal(lsd)figure(1);subplot(1,2,1)plot(sp(1:nsp,1),sp(1:nsp,2),'m+');holdonplot(sn(1:nsn,1),sn(1:nsn,2),'c*');subplot(1,2,2)%svmStruct=svmtrain(sd,Y,'Kernel_Function','linear','showplot',true);svmStruct=svmtrain(sd,Y,'Kernel_Function','quadratic','showplot',true);%usethetrainedsvm(svmStruct)toclassifythedataRD=svmclassify(svmStruct,sd,'showplot',true)%RDistheclassificationresultvector0.3GaussianKernalClassificationclearall;closeallclc;sp=[5,4.5;3,7;6,6;4,6;5,6.5]%positivesamplepointsnsp=size(sp);sn=[1,2;3,5;7,3;3,4;6,2.7;4,3;2,7]%negativesamplepointsnsn=size(sn)sd=[sp;sn]lsd=[truetruetruetruetruefalsefalsefalsefalsefalsefalsefalse]Y=nominal(lsd)figure(1);subplot(1,2,1)plot(sp(1:nsp,1),sp(1:nsp,2),'m+');holdonplot(sn(1:nsn,1),sn(1:nsn,2),'c*');subplot(1,2,2)svmStruct=svmtrain(sd,Y,'Kernel_Function','rbf','rbf_sigma',0.6,'method','SMO','showplot',true);%svmStruct=svmtrain(sd,Y,'Kernel_Function','quadratic','showplot',true);%usethetrainedsvm(svmStruct)toclassifythedataRD=svmclassify(svmStruct,sd,'showplot',true)%RDistheclassificationresultvectorsvmtrain(sd,Y,'Kernel_Function','rbf','rbf_sigma',0.2,'method','SMO','showplot',true);0.4SvmtrainFunctionsvmtrainTrainasupportvectormachineclassifierSVMSTRUCT=svmtrain(TRAINING,Y)trainsasupportvectormachine(SVM)classifierondatatakenfromtwogroups.TRAININGisanumericmatrixofpredictordata.RowsofTRAININGcorrespondtoobservations;columnscorrespondtofeatures.YisacolumnvectorthatcontainstheknownclasslabelsforTRAINING.Yisagroupingvariable,i.e.,itcanbeacategorical,numeric,orlogicalvector;acellvectorofstrings;oracharactermatrixwitheachrowrepresentingaclasslabel(seehelpforgroupingvariable).EachelementofYspecifiesthegroupthecorrespondingrowofTRAININGbelongsto.TRAININGandYmusthavethesamenumberofrows.SVMSTRUCTcontainsinformationaboutthetrainedclassifier,includingthesupportvectors,thatisusedbySVMCLASSIFYforclassification.svmtraintreatsNaNs,emptystringsor'undefined'valuesasmissingvaluesandignoresthecorrespondingrowsinTRAININGandY.SVMSTRUCT=svmtrain(TRAINING,Y,'PARAM1',val1,'PARAM2',val2,...)specifiesoneormoreofthefollowingname/valuepairs:NameValue'kernel_function'Astringorafunctionhandlespecifyingthekernelfunctionusedtorepresentthedotproductinanewspace.Thevaluecanbeoneofthefollowing:'linear'-Linearkernelordotproduct(default).Inthiscase,svmtrainfindstheoptimalseparatingplaneintheoriginalspace.'quadratic'-Quadratickernel'polynomial'-Polynomialkernelwithdefaultorder3.Tospecifyanotherorder,usethe'polyorder'argument.'rbf'-GaussianRadialBasisFunctionwithdefaultscalingfactor1.Tospecifyanotherscalingfactor,usethe'rbf_sigma'argument.'mlp'-MultilayerPerceptronkernel(MLP)withdefaultweight1anddefaultbias-1.Tospecifyanotherweightorbias,usethe'mlp_params'argument.function-Akernelfunctionspecifiedusing@(forexample@KFUN),orananonymousfunction.AkernelfunctionmustbeoftheformfunctionK=KFUN(U,V)Thereturnedvalue,K,isamatrixofsizeM-by-N,whereMandNarethenumberofrowsinUandVrespectively.'rbf_sigma'ApositivenumberspecifyingthescalingfactorintheGaussianradialbasisfunctionkernel.Defaultis1.'polyorder'Apositiveintegerspecifyingtheorderofthepolynomialkernel.Defaultis3.'mlp_params'Avector[P1P2]specifyingtheparametersofMLPkernel.TheMLPkerneltakestheform:K=tanh(P1*U*V'+P2),whereP10andP20.Defaultis[1,-1].'method'Astringspecifyingthemethodusedtofindtheseparatinghyperplane.Choicesare:'SMO'-SequentialMinimalOptimization(SMO)method(default).ItimplementstheL1soft-marginSVMclassifier.'QP'-Quadraticprogramming(requiresanOptimizationToolboxlicense).ItimplementstheL2soft-marginSVMclassifier.Method'QP'doesn'tscalewellforTRAININGwithlargenumberofobservations.'LS'-Least-squaresmethod.ItimplementstheL2soft-marginSVMclassifier.'options'OptionsstructurecreatedusingeitherSTATSETorOPTIMSET.*Whenyouset'method'to'SMO'(default),createtheoptionsstructureusingSTATSET.Applicableoptions:'Display'Levelofdisplayoutput.Choicesare'off'(thedefault),'iter',and'final'.Value'iter'reportsevery500i

1 / 59
下载文档,编辑使用

©2015-2020 m.777doc.com 三七文档.

备案号:鲁ICP备2024069028号-1 客服联系 QQ:2149211541

×
保存成功