资源描述:
《支持向量机matlab实现源代码知识讲解.doc》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、支持向量机matlab实现源代码精品文档editsvmtrain>>editsvmclassify>>editsvmpredictfunction[svm_struct,svIndex]=svmtrain(training,groupnames,varargin)%SVMTRAINtrainsasupportvectormachineclassifier%%SVMStruct=SVMTRAIN(TRAINING,GROUP)trainsasupportvectormachine%classifierusingdataTRAININGtakenfromtwogroupsgivenbyGRO
2、UP.%SVMStructcontainsinformationaboutthetrainedclassifierthatis%usedbySVMCLASSIFYforclassification.GROUPisacolumnvectorof%valuesofthesamelengthasTRAININGthatdefinestwogroups.Each%elementofGROUPspecifiesthegroupthecorrespondingrowofTRAINING%belongsto.GROUPcanbeanumericvector,astringarray,oracell%a
3、rrayofstrings.SVMTRAINtreatsNaNsoremptystringsinGROUPas%missingvaluesandignoresthecorrespondingrowsofTRAINING.%%SVMTRAIN(...,'KERNEL_FUNCTION',KFUN)allowsyoutospecifythekernel%functionKFUNusedtomapthetrainingdataintokernelspace.The%defaultkernelfunctionisthedotproduct.KFUNcanbeoneofthe%followings
4、tringsorafunctionhandle:%%'linear'Linearkernelordotproduct%'quadratic'Quadratickernel%'polynomial'Polynomialkernel(defaultorder3)%'rbf'GaussianRadialBasisFunctionkernel%'mlp'MultilayerPerceptronkernel(defaultscale1)%functionAkernelfunctionspecifiedusing@,%forexample@KFUN,orananonymousfunction%%Ak
5、ernelfunctionmustbeoftheform%%functionK=KFUN(U,V)%%Thereturnedvalue,K,isamatrixofsizeM-by-N,whereUandVhaveM%andNrowsrespectively.IfKFUNisparameterized,youcanuse%anonymousfunctionstocapturetheproblem-dependentparameters.For%example,supposethatyourkernelfunctionis%%functionk=kfun(u,v,p1,p2)%k=tanh(
6、p1*(u*v')+p2);%%Youcansetvaluesforp1andp2andthenuseananonymousfunction:%@(u,v)kfun(u,v,p1,p2).收集于网络,如有侵权请联系管理员删除精品文档%%SVMTRAIN(...,'POLYORDER',ORDER)allowsyoutospecifytheorderofa%polynomialkernel.Thedefaultorderis3.%%SVMTRAIN(...,'MLP_PARAMS',[P1P2])allowsyoutospecifythe%parametersoftheMultilayer
7、Perceptron(mlp)kernel.Themlpkernel%requirestwoparameters,P1andP2,whereK=tanh(P1*U*V'+P2)andP1%>0andP2<0.DefaultvaluesareP1=1andP2=-1.%%SVMTRAIN(...,'METHOD',METHOD)allowsyoutospecifythemethodused%tofindtheseparatinghyp