支持向量机matlab实现源代码

上传人:公**** 文档编号:557844877 上传时间:2023-12-20 格式:DOC 页数:8 大小:40.50KB
返回 下载 相关 举报
支持向量机matlab实现源代码_第1页
第1页 / 共8页
支持向量机matlab实现源代码_第2页
第2页 / 共8页
支持向量机matlab实现源代码_第3页
第3页 / 共8页
支持向量机matlab实现源代码_第4页
第4页 / 共8页
支持向量机matlab实现源代码_第5页
第5页 / 共8页
点击查看更多>>
资源描述

《支持向量机matlab实现源代码》由会员分享,可在线阅读,更多相关《支持向量机matlab实现源代码(8页珍藏版)》请在金锄头文库上搜索。

1、editsvmtraineditsvmclassifyeditsvmpredictfunctionsvm_struct,svIndex=svmtrain(training,groupnames,varargin)%SVMTRAINtrainsasupportvectormachineclassifier%SVMStruct=SVMTRAIN(TRAINING,GROUP)trainsasupportvectormachine%classifierusingdataTRAININGtakenfromtwogroupsgivenbyGROUP.%SVMStructcontainsinformati

2、onaboutthetrainedclassifierthatis%usedbySVMCLASSIFYforclassification.GROUPisacolumnvectorof%valuesofthesamelengthasTRAININGthatdefinestwogroups.Each%elementofGROUPspecifiesthegroupthecorrespondingrowofTRAINING%belongsto.GROUPcanbeanumericvector,astringarray,oracell%arrayofstrings.SVMTRAINtreatsNaNso

3、remptystringsinGROUPas%missingvaluesandignoresthecorrespondingrowsofTRAINING.%SVMTRAIN(.,KERNEL_FUNCTION,KFUN)allowsyoutospecifythekernel%functionKFUNusedtomapthetrainingdataintokernelspace.The%defaultkernelfunctionisthedotproduct.KFUNcanbeoneofthe%followingstringsorafunctionhandle:%linearLinearkern

4、elordotproduct%quadraticQuadratickernel%polynomialPolynomialkernel(defaultorder3)%rbfGaussianRadialBasisFunctionkernel%mlpMultilayerPerceptronkernel(defaultscale1)%functionAkernelfunctionspecifiedusing,%forexampleKFUN,orananonymousfunction%Akernelfunctionmustbeoftheform%functionK=KFUN(U,V)%Thereturn

5、edvalue,K,isamatrixofsizeM-by-N,whereUandVhaveM%andNrowsrespectively.IfKFUNisparameterized,youcanuse%anonymousfunctionstocapturetheproblem-dependentparameters.For%example,supposethatyourkernelfunctionis%functionk=kfun(u,v,p1,p2)%k=tanh(p1*(u*v)+p2);%Youcansetvaluesforp1andp2andthenuseananonymousfunc

6、tion:%(u,v)kfun(u,v,p1,p2).%SVMTRAIN(.,POLYORDER,ORDER)allowsyoutospecifytheorderofa%polynomialkernel.Thedefaultorderis3.%SVMTRAIN(.,MLP_PARAMS,P1P2)allowsyoutospecifythe%parametersoftheMultilayerPerceptron(mlp)kernel.Themlpkernel%requirestwoparameters,P1andP2,whereK=tanh(P1*U*V+P2)andP1%0andP20.Def

7、aultvaluesareP1=1andP2=-1.%SVMTRAIN(.,METHOD,METHOD)allowsyoutospecifythemethodused%tofindtheseparatinghyperplane.Optionsare%QPUsequadraticprogramming(requirestheOptimizationToolbox)%LSUseleast-squaresmethod%IfyouhavetheOptimizationToolbox,thentheQPmethodisthedefault%method.Ifnot,theonlyavailablemet

8、hodisLS.%SVMTRAIN(.,QUADPROG_OPTS,OPTIONS)allowsyoutopassanOPTIONS%structurecreatedusingOPTIMSETtotheQUADPROGfunctionwhenusing%theQPmethod.Seehelpoptimsetformoredetails.%SVMTRAIN(.,SHOWPLOT,true),whenusedwithtwo-dimensionaldata,%createsaplotofthegroupeddataandplotstheseparatinglinefor%theclassifier.

9、%Example:%Loadthedataandselectfeaturesforclassification%loadfisheriris%data=meas(:,1),meas(:,2);%ExtracttheSetosaclass%groups=ismember(species,setosa);%Randomlyselecttrainingandtestsets%train,test=crossvalind(holdOut,groups);%cp=classperf(groups);%Usealinearsupportvectormachineclassifier%svmStruct=s

10、vmtrain(data(train,:),groups(train),showplot,true);%classes=svmclassify(svmStruct,data(test,:),showplot,true);%Seehowwelltheclassifierperformed%classperf(cp,classes,test);%cp.CorrectRate%SeealsoCLASSIFY,KNNCLASSIFY,QUADPROG,SVMCLASSIFY.%Copyright2004TheMathWorks,Inc.%$Revision:1.1.12.1$Date:2004/12/

11、2420:43:35$%References:%1Kecman,V,LearningandSoftComputing,%MITPress,Cambridge,MA.2001.%2Suykens,J.A.K.,VanGestel,T.,DeBrabanter,J.,DeMoor,B.,%Vandewalle,J.,LeastSquaresSupportVectorMachines,%WorldScientific,Singapore,2002.%3Scholkopf,B.,Smola,A.J.,LearningwithKernels,%MITPress,Cambridge,MA.2002.%SV

12、MTRAIN(.,KFUNARGS,ARGS)allowsyoutopassadditional%argumentstokernelfunctions.%setdefaultsplotflag=false;qp_opts=;kfunargs=;setPoly=false;usePoly=false;setMLP=false;useMLP=false;ifisempty(which(quadprog)useQuadprog=true;elseuseQuadprog=false;end%setdefaultkernelfunctionkfun=linear_kernel;%checkinputsifnargin0training(nans,:)=;g(nans)=;endngroups=length(groupString);ifngroups2error(Bioinfo:svmtrain:TooManyGroups,.SVMTRAINonlysupportsclassificationintotwogroups.nGROUPcontains%ddifferentgroups.,ngroups)end%convertto1,-1.g=1-(2*(g-1);%handleopt

展开阅读全文
相关资源
正为您匹配相似的精品文档
相关搜索

最新文档


当前位置:首页 > 办公文档 > 解决方案

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号