您好,欢迎访问三七文档
当前位置:首页 > 临时分类 > 支持向量机的matlab代码
支持向量机的matlab代码Matlab中关于evalin帮助:EVALIN(WS,'expression')evaluates'expression'inthecontextoftheworkspaceWS.WScanbe'caller'or'base'.ItissimilartoEVALexceptthatyoucancontrolwhichworkspacetheexpressionisevaluatedin.[X,Y,Z,...]=EVALIN(WS,'expression')returnsoutputargumentsfromtheexpression.EVALIN(WS,'try','catch')triestoevaluatethe'try'expressionandifthatfailsitevaluatesthe'catch'expression(inthecurrentworkspace).可知evalin('base','algo')是对工作空间base中的algo求值(返回其值)。如果是7.0以上版本editsvmtraineditsvmclassifyeditsvmpredictfunction[svm_struct,svIndex]=svmtrain(training,groupnames,varargin)%SVMTRAINtrainsasupportvectormachineclassifier%%SVMStruct=SVMTRAIN(TRAINING,GROUP)trainsasupportvectormachine%classifierusingdataTRAININGtakenfromtwogroupsgivenbyGROUP.%SVMStructcontainsinformationaboutthetrainedclassifierthatis%usedbySVMCLASSIFYforclassification.GROUPisacolumnvectorof%valuesofthesamelengthasTRAININGthatdefinestwogroups.Each%elementofGROUPspecifiesthegroupthecorrespondingrowofTRAINING%belongsto.GROUPcanbeanumericvector,astringarray,oracell%arrayofstrings.SVMTRAINtreatsNaNsoremptystringsinGROUPas%missingvaluesandignoresthecorrespondingrowsofTRAINING.%%SVMTRAIN(...,'KERNEL_FUNCTION',KFUN)allowsyoutospecifythekernel%functionKFUNusedtomapthetrainingdataintokernelspace.The%defaultkernelfunctionisthedotproduct.KFUNcanbeoneofthe%followingstringsorafunctionhandle:%%'linear'Linearkernelordotproduct%'quadratic'Quadratickernel%'polynomial'Polynomialkernel(defaultorder3)%'rbf'GaussianRadialBasisFunctionkernel%'mlp'MultilayerPerceptronkernel(defaultscale1)%functionAkernelfunctionspecifiedusing@,%forexample@KFUN,orananonymousfunction%%Akernelfunctionmustbeoftheform%%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(p1*(u*v')+p2);%%Youcansetvaluesforp1andp2andthenuseananonymousfunction:%@(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.DefaultvaluesareP1=1andP2=-1.%%SVMTRAIN(...,'METHOD',METHOD)allowsyoutospecifythemethodused%tofindtheseparatinghyperplane.Optionsare%%'QP'Usequadraticprogramming(requirestheOptimizationToolbox)%'LS'Useleast-squaresmethod%%IfyouhavetheOptimizationToolbox,thentheQPmethodisthedefault%method.Ifnot,theonlyavailablemethodisLS.%%SVMTRAIN(...,'QUADPROG_OPTS',OPTIONS)allowsyoutopassanOPTIONS%structurecreatedusingOPTIMSETtotheQUADPROGfunctionwhenusing%the'QP'method.Seehelpoptimsetformoredetails.%%SVMTRAIN(...,'SHOWPLOT',true),whenusedwithtwo-dimensionaldata,%createsaplotofthegroupeddataandplotstheseparatinglinefor%theclassifier.%%Example:%%Loadthedataandselectfeaturesforclassification%loadfisheriris%data=[meas(:,1),meas(:,2)];%%ExtracttheSetosaclass%groups=ismember(species,'setosa');%%Randomlyselecttrainingandtestsets%[train,test]=crossvalind('holdOut',groups);%cp=classperf(groups);%%Usealinearsupportvectormachineclassifier%svmStruct=svmtrain(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/2420:43:35$%References:%[1]Kecman,V,LearningandSoftComputing,%MITPress,Cambridge,MA.2001.%[2]Suykens,J.A.K.,VanGestel,T.,DeBrabanter,J.,DeMoor,B.,%Vandewalle,J.,LeastSquaresSupportVectorMachines,%WorldScientific,Singapore,2002.%[3]Scholkopf,B.,Smola,A.J.,LearningwithKernels,%MITPress,Cambridge,MA.2002.%%SVMTRAIN(...,'KFUNARGS',ARGS)allowsyoutopassadditional%argumentstokernelfunctions.%setdefaultsplotflag=false;qp_opts=[];kfunargs={};setPoly=false;usePoly=false;setMLP=false;useMLP=false;if~isempty(which('quadprog'))useQuadprog=true;elseuseQuadprog=false;end%setdefaultkernelfunctionkfun=@linear_kernel;%checkinputsifnargin2error(nargchk(2,Inf,nargin))endnumoptargs=nargin-2;optargs=varargin;%grp2idxsortsanumericgroupingvarascending,andastringgrouping%varbyorderoffirstoccurrence[g,groupString]=grp2idx(groupnames);%checkgroupisavector--thoughcharinputisspecial...if~isvector(groupnames)&&~ischar(groupnames)error('Bioinfo:svmtrain:GroupNotVector',...'Groupmustbeavector.');end%makesurethatthedataiscorrectlyoriented.ifsize(groupnames,1)==1groupnames=groupnames';end%makesuredataistherightsizen=length(groupnames);ifsize(training,1)~=nifsize(training,2)==ntraining=training';elseerror('Bioinfo:svmtrain:DataGroupSizeMismatch',...'GROUPandTRAININGmusthavethesamenumberofrows.')endend%NaNsaretreatedasunknownclassesandareremovedfromthetraining%datanans=find(isnan(g));iflength(nans)0training(nans,:)=[];g(nans)=[];endngroups=length(gr
本文标题:支持向量机的matlab代码
链接地址:https://www.777doc.com/doc-3232311 .html