支持向量机matlab实现源代码

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

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

1、edit svmtrainedit svmclassfyedit svmpredictfun cti on svm_struct, svln dex = svmtra in (tra ining, group names, vararg in)%SVMTRAIN trai ns a support vector mach ine classier% SVMStruct = SVMTRAIN(TRAINING,GROUPtra ins a support vector mach ine% classifier using data TRAINING taken from tw groups gv

2、en by GROUP% SVMStruct contains inf ormati on about the tra ined classifier that is% used by SVMCLASSIFY for classifcatio n. GROUPis a colu mn vector of% values of the same len gth as TRAINING that defi nes two groups.ach% eleme nt of GROUPspecifies the group the corresp on di ng rw of TRAINING% bel

3、 ongs to. GROUPca n be a nu meric vector, a stri ng array, or a cell% array of stri ngs. SVMTRAIN treats NaNs or empty str ings in GROUPis% missi ng values and ign ores the corresp onding rows of TRAINING.% SVMTRAIN(.,KERNE_FUNCTION,KFUN) allows you to specfy the ker nel% fun ctio n KFUN used to map

4、 the trai ning data into ker nel space. The% default kernel fun ctio n is the dot product. KFUN can be one of the% follow ing str ings or a fun cti on han dle:% li near Lin ear ker nel or dot product% quadratic Quadratic ker nel% po lyno mia l Fblyno mial ker nel (default order 3)% rbf Gaussia n Rad

5、ial Basis Fun cti on ker nel% mlp Multilayer ferceptr on ker nel (default scale 1)% fun ctio n A ker nel fun cti on spedied using ,% for example KFUN, or an anonym ous fun cti on% A ker nel fun cti on must be of the form% fun ctio n K = KFUN(U, V)% The retur ned value, K, is a matrix of size M-by-N,

6、 where U and V have M% and N rows respectively. If KFUN is parameterized, you can use% anonym ous fun cti ons to capture the problem-depe ndent parameters. For% example, suppose that your ker nel fun ctio n is% fun ctio n k = kfun (u,v,p1,p2)% k = tan h(p1*(u*v)+p2);% % You can set values for pl and

7、 p2 and the n use an anonym ous fun ctio n: % (u,v) kfun (u,v,p1,p2).% SVMTRAIN(.,POLYORDER,ORDER) allows you to specify the order of a% polyno mial ker nel. The default orders 3.% SVMTRAIN(.,MLF_PARAMS,P1 P2) allows you to specfy the% parameters of the Multilayer Prceptro n (mlp) ker nel. The mlp k

8、ernel% requires two parameters, P and P2, where K = tan h(PI*U*V + P2) and P1% 0 and F2 0. Default values are P = 1 and P2 = -1.% SVMTRAIN(.,METHOD,METHOD) allow you to specify the method used% to find the separati ng hyperpla ne. Opti ons are% QP Use quadratic program ming (requires the Optimizatio

9、 n Toolbox)% LS Use least-squares method% If you have the Optimizati on Toolbox, the n the QPnethod is the default% method. If not, the only available method is LS.% SVMTRAIN(.,QUADPROG_OTS,OPTIONS) allows you to pass an OPTIONS% structure created usi ng OITIMSET to the QUADPROG fun ction whe n usin

10、g% the QP method. See help optimset for more details.% SVMTRAIN(.,SHOWLOT,true), whe n usedw ith two-dime nsio nal data,% creates a plot of the grouped data and plots the separat ing line for% the classifier.% Example:% % Load the data and select features for clasficatio n% load fisheriris% data = m

11、eas(:,1), meas(:,2);% % Extract the Setosa class% groups = ismember(speciessetosa);% % Ran domly select tra ining and test sets% tra in, test = crossvali nd(holdOut,groups);% cp = classperf(groups);% % Use a lin ear support vector mach ine clasfeier% svmStruct = svmtrai n(data(tra in ,:),groups(trai

12、 nshowplot,true);% classes = svmclassfy(svmStruct,data(test,:)Showplot,true);% % See how well the classifier performed% classperf(cp,classes,test);% cp.CorrectRate% See also CLASSIFY, KNNCLASSIFY, QUADPROG, SVMCLASSIFY.% Copyright 2004 The MathWorks, I nc.% $Revisio n: 1.1.12.1 $ $Date: 2004/12/24 2

13、0:43:35 $% Refere nces:% 1 Kecma n, V, Lear ning and Soft Computi ng,% MIT Press, Cambridge, MA. 2001.% 2 Suyke ns, J.A.K., Van Gestel, T., De Braba nter, J., De Moor, B.,% Van dewalle, J., Least Squares Support Vector Mach in es,% World Scie ntfic. Sin gapore, 2002.% Scholkopf, B., Smola, A.J., Lea

14、r ning Wh Ker nes,% MIT Press, Cambridge, MA. 2002.% SVMTRAIN(.,KFUNARGS,ARGS) allow you to pass additio nal% argume nts to ker nel fun cti ons.% set defaultsplotflag = false;qp_opts =;kfun args = ;setPoly = false; usePbly = false;setMLP= false; useMLP= false;if isempty(whch(quadprog)useQuadprog = t

15、rue;elseuseQuadprog = fase;end% set default ker nel fun cti onkfun = li near_ker nel;% check in putsif n arg in 2error( nargchk(2,l nf, narg in)endnum optargs = n arg in -2;optargs = vararg in;% grp2idx sorts a nu meric group ing var asce nding, and a stri ng group ing% var by order of first occurre nee g,groupStri ng = grp2idx(group names); % check group s a vector - though char in puts special.if isvector(group names) & ischar(group names)error(Bio

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

最新文档


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

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