




已阅读5页,还剩30页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
支持向量机的matlab代码Matlab中关于evalin帮助: EVALIN(WS,expression) evaluates expression in the context of the workspace WS. WS can be caller or base. It is similar to EVAL except that you can control which workspace the expression is evaluated in. X,Y,Z,. = EVALIN(WS,expression) returns output arguments from the expression. EVALIN(WS,try,catch) tries to evaluate the try expression and if that fails it evaluates the catch expression (in the current workspace). 可知evalin(base, algo)是对工作空间base中的algo求值(返回其值)。如果是7.0以上版本 edit svmtrain edit svmclassify edit svmpredict function svm_struct, svIndex = svmtrain(training, groupnames, varargin) %SVMTRAIN trains a support vector machine classifier % % SVMStruct = SVMTRAIN(TRAINING,GROUP) trains a support vector machine % classifier using data TRAINING taken from two groups given by GROUP. % SVMStruct contains information about the trained classifier that is % used by SVMCLASSIFY for classification. GROUP is a column vector of % values of the same length as TRAINING that defines two groups. Each % element of GROUP specifies the group the corresponding row of TRAINING % belongs to. GROUP can be a numeric vector, a string array, or a cell % array of strings. SVMTRAIN treats NaNs or empty strings in GROUP as % missing values and ignores the corresponding rows of TRAINING. % % SVMTRAIN(.,KERNEL_FUNCTION,KFUN) allows you to specify the kernel % function KFUN used to map the training data into kernel space. The % default kernel function is the dot product. KFUN can be one of the % following strings or a function handle: % % linear Linear kernel or dot product % quadratic Quadratic kernel % polynomial Polynomial kernel (default order 3) % rbf Gaussian Radial Basis Function kernel % mlp Multilayer Perceptron kernel (default scale 1) % function A kernel function specified using , % for example KFUN, or an anonymous function % % A kernel function must be of the form % % function K = KFUN(U, V) % % The returned value, K, is a matrix of size M-by-N, where U and V have M % and N rows respectively. If KFUN is parameterized, you can use % anonymous functions to capture the problem-dependent parameters. For % example, suppose that your kernel function is % % function k = kfun(u,v,p1,p2) % k = tanh(p1*(u*v)+p2); % % You can set values for p1 and p2 and then use an anonymous function: % (u,v) kfun(u,v,p1,p2). % % SVMTRAIN(.,POLYORDER,ORDER) allows you to specify the order of a % polynomial kernel. The default order is 3. % % SVMTRAIN(.,MLP_PARAMS,P1 P2) allows you to specify the % parameters of the Multilayer Perceptron (mlp) kernel. The mlp kernel % requires two parameters, P1 and P2, where K = tanh(P1*U*V + P2) and P1 % 0 and P2 0. Default values are P1 = 1 and P2 = -1. % % SVMTRAIN(.,METHOD,METHOD) allows you to specify the method used % to find the separating hyperplane. Options are % % QP Use quadratic programming (requires the Optimization Toolbox) % LS Use least-squares method % % If you have the Optimization Toolbox, then the QP method is the default % method. If not, the only available method is LS. % % SVMTRAIN(.,QUADPROG_OPTS,OPTIONS) allows you to pass an OPTIONS % structure created using OPTIMSET to the QUADPROG function when using % the QP method. See help optimset for more details. % % SVMTRAIN(.,SHOWPLOT,true), when used with two-dimensional data, % creates a plot of the grouped data and plots the separating line for % the classifier. % % Example: % % Load the data and select features for classification % load fisheriris % data = meas(:,1), meas(:,2); % % Extract the Setosa class % groups = ismember(species,setosa); % % Randomly select training and test sets % train, test = crossvalind(holdOut,groups); % cp = classperf(groups); % % Use a linear support vector machine classifier % svmStruct = svmtrain(data(train,:),groups(train),showplot,true); % classes = svmclassify(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, Inc. % $Revision: 1.1.12.1 $ $Date: 2004/12/24 20:43:35 $ % References: % 1 Kecman, V, Learning and Soft Computing, % MIT Press, Cambridge, MA. 2001. % 2 Suykens, J.A.K., Van Gestel, T., De Brabanter, J., De Moor, B., % Vandewalle, J., Least Squares Support Vector Machines, % World Scientific, Singapore, 2002. % 3 Scholkopf, B., Smola, A.J., Learning with Kernels, % MIT Press, Cambridge, MA. 2002. % % SVMTRAIN(.,KFUNARGS,ARGS) allows you to pass additional % arguments to kernel functions. % set defaults plotflag = false; qp_opts = ; kfunargs = ; setPoly = false; usePoly = false; setMLP = false; useMLP = false; if isempty(which(quadprog) useQuadprog = true; else useQuadprog = false; end % set default kernel function kfun = linear_kernel; % check inputs if nargin 0 training(nans,:) = ; g(nans) = ; end ngroups = length(groupString); if ngroups 2 error(Bioinfo:svmtrain:TooManyGroups,. SVMTRAIN only supports classification into two groups.nGROUP contains %d different groups.,ngroups) end % convert to 1, -1. g = 1 - (2* (g-1); % handle optional arguments if numoptargs = 1 if rem(numoptargs,2)= 1 error(Bioinfo:svmtrain:IncorrectNumberOfArguments,. Incorrect number of arguments to %s.,mfilename); end okargs = kernel_function,method,showplot,kfunargs,quadprog_opts,polyorder,mlp_params; for j=1:2:numoptargs pname = optargsj; pval = optargsj+1; k = strmatch(lower(pname), okargs);%#ok if isempty(k) error(Bioinfo:svmtrain:UnknownParameterName,. Unknown parameter name: %s.,pname); elseif length(k)1 error(Bioinfo:svmtrain:AmbiguousParameterName,. Ambiguous parameter name: %s.,pname); else switch(k) case 1 % kernel_function if ischar(pval) okfuns = linear,quadratic,. radial,rbf,polynomial,mlp; funNum = strmatch(lower(pval), okfuns);%#ok if isempty(funNum) funNum = 0; end switch funNum %maybe make this less strict in the future case 1 kfun = linear_kernel; case 2 kfun = quadratic_kernel; case 3,4 kfun = rbf_kernel; case 5 kfun = poly_kernel; usePoly = true; case 6 kfun = mlp_kernel; useMLP = true; otherwise error(Bioinfo:svmtrain:UnknownKernelFunction,. Unknown Kernel Function %s.,kfun); end elseif isa (pval, function_handle) kfun = pval; else error(Bioinfo:svmtrain:BadKernelFunction,. The kernel function input does not appear to be a function handlenor valid function name.) end case 2 % method if strncmpi(pval,qp,2) useQuadprog = true; if isempty(which(quadprog) warning(Bioinfo:svmtrain:NoOptim,. The Optimization Toolbox is required to use the quadratic programming method.) useQuadprog = false; end elseif strncmpi(pval,ls,2) useQuadprog = false; else error(Bioinfo:svmtrain:UnknownMethod,. Unknown method option %s. Valid methods are QP and LS,pval); end case 3 % display if pval = 0 if size(training,2) = 2 plotflag = true; else warning(Bioinfo:svmtrain:OnlyPlot2D,. The display option can only plot 2D training data.) end end case 4 % kfunargs if iscell(pval) kfunargs = pval; else kfunargs = pval; end case 5 % quadprog_opts if isstruct(pval) qp_opts = pval; elseif iscell(pval) qp_opts = optimset(pval:); else error(Bioinfo:svmtrain:BadQuadprogOpts,. QUADPROG_OPTS must be an opts structure.); end case 6 % polyorder if isscalar(pval) | isnumeric(pval) error(Bioinfo:svmtrain:BadPolyOrder,. POLYORDER must be a scalar value.); end if pval =floor(pval) | pval sqrt(eps); sv = training(svIndex,:); % calculate the parameters of the separating line from the support % vectors. alphaHat = g(svIndex).*alpha(svIndex); % Calculate the bias by applying the indicator function to the support % vector with largest alpha. maxAlpha,maxPos = max(alpha); %#ok bias = g(maxPos) - sum(alphaHat.*kx(svIndex,maxPos); % an alternative method is to average the values over all support vectors % bias = mean(g(sv) - sum(alphaHat(:,ones(1,numSVs).*kx(sv,sv); % An alternative way to calculate support vectors is to look for zeros of % the Lagrangians (fifth output from QUADPROG). % % alpha,fval,output,exitflag,t = quadprog(H,-ones(n,1),. % g,0,zeros(n,1),inf *ones(n,1),zeros(n,1),opts); % % sv = t.lower sqrt(eps) & t.upper 0,其余都为0),则最佳的权向量w也就可以利用(3-90)式定下来,它们是这些支持向量数据的线性求和。如图3-29所示:图3.29 如果知道哪些数据是支持向量,哪些不是,则问题就简单了。问题在于哪些数据是支持向量事先并不能确定,因此这只有通过求(3-84)式的极大值来求解。 从(3-85)可以看出,只要最佳的ai求得(表示成),则(3-90)为了求出最佳的ai,拉格朗日理论中引入一种对偶函数,与(3-84)式相对偶的函数的构造方法是:对L(W,a) 分别求它对W及w0的偏微分,并置为零,然后再代回到(3-84)式中,从而得到 (3-91)拉格朗日理论证明:满足上述条件(3-85)到(3-89)时,找(3-91)式极大值的解就是(3-84)式的条件极小值,因此由(3-91)可求得各个最佳值,代入(3-90)即可得到,在W确定之后w0值也可利用(3-88)对某个的数据求出。对(3-91)式的来源不要求弄懂,只需知道,它的极大值解与(3-84)式的极小值解是一致的就行了。因为后面还要用(3-91)说明一些问题。svm讲座10.31 天晚上的讲座的内容是怎样用支持向量机进行数据预测jungle192008-10-31 20:15:18利用支持向量机进行数据预测一般分为三个步骤:数据的选择,数据的预处理,模型的训练jungle192008-10-31 20:17:03从现场采集的数据一般也是按照时间序列进行分布,因此在选择数据时要选择出每一个时间段的数据进行模型训练和模型测试jungle192008-10-31 20:20:04在项目中我的处理一般是这样的,跳格选择数据,具体做法就是将数据按照时间序列排列,然后每三个选择出一个来进行模型的测试,剩下的用来模型训练,这样,就可以有2/3训练,1/3测试,一般这样的安排比较合理jungle192008-10-31 20:23:32在挑选数据的时候,还有一个要值得注意的就是,要将数据集中的最大和最小值挑选到训练集中,这样,使得在训练网络的时候能确定支持向量机网络的界,测试的时候,不会有数据超出训练网络的界,减少训练误差jungle192008-10-31 20:28:07数据选择后的就是数据处理,这是关系着模型精确度的重要一步jungle192008-10-31 20:33:24凡是做过模型的人都知道,数据处理的第一步就是主元分析,去掉相关性比较大的属性,这一步在我认为是做项目初期,不知道数据属性间的相关度的时候用的方法,在后来的数据中属性都是挑选好的,没有必要再进行这一步,而且,很多人都是用的matlab中自带的主元分析程序,而对于多小的相关度是应该保留的,很多人没有一个直接的概念jungle192008-10-31 20:36:17在数据挖掘中,对于属性的选择有这样的两个原则,一是所选择的属性要包含尽量多的数据信息,二是属性间的相关性尽量地小,一般情况下是很难做到两个要求都是最优的,因此,往往要根据数据来确定两者间的一个切合点waveletz2008-10-31 20:41:05能不能举一个实例?waveletz2008-10-31 20:41:30最好先把实例贴到论坛中,让大家先了解一下jungle192008-10-31 20:42:28归一化处理数据是要将数据属性的量纲统一。一般的是将数据归一到-1 1之间,在这里要说明的是,在一般实际应用中还是不要选择负数的好,避免由于负数而产生的其他一系列问题,当然,有的时候又不得不用负数。归一化的思想就是这样的一个函数D=(D-Dmin)/(Dmax-Dmin),为了防止出现峰值,在求取最大最小值时一般将数值范围方法20%jungle192008-10-31 20:43:12一般将数值范围放大20%jungle192008-10-31 20:44:16呵呵,不好意思,这个要是以例子来说的话,今天的时间是不够的,所以我只能泛泛讲一讲在论坛上有很多人问到这样的一个问题,就是如何将输出数据反归一化,在我看来,归一化也是一中数据变换,或多或少地改变了数据的原有信息,在这样的情况下,输出数据一般是不进行归一化的jungle192008-10-31 20:49:16以上讲的是数据预处理的两个必须的过程,接下来的数据处理的方法就是依照各个数据集来定的,有的数据比较好,单模型就可以达到工艺要求,那就没有必要再进行处理了loolojoan2008-10-31 20:52:37小木草:关于跳格选择数据:比如说我要对月输出数据做预测,那训练数据怎末选择?现有好几年的数据jungle192008-10-31 20:58:44to 小木草:对于你这个问题,说明你的数据是比较少的了,就算是好几年的数据,那也不会超过100组吧,这样的情况时比较难做的,因为你的时间拉得太长了,可以利用增加数据的方法来进行数据的补充,还有一中方法就是也看作一个时间序列进行选择jungle192008-10-31 21:01:56对于数据不是很好的情况,一般的是数据包含的噪声较大,要进行去噪处理,去噪处理的方法比较多,用得比较多的是小波去噪,小波去噪存在的一个问题就是,往往会改变幅值,这个在很多信号处理的时候,幅值对信号的传输是很重要的,个人所用的是滑动平均法进行数据噪声的去除loolojoan2008-10-31 21:03:14小木草:我想做短期数据的预测,比方说用好几年的数据预测下一年或者下几个月的数据,这样的情况怎么处理?jungle192008-10-31 21:06:05这样的话你就把时间序列这一内含属性忽略jungle192008-10-31 21:08:21还有一些数据处理的方法,比如说聚类,这是做多模型的前序,当数据的跳变较大,选择多模型的效果往往比单模型的效果要好jungle192008-10-31 21:10:03支持向量机同神经网络一样,也存在一个拟合能力的问题,当用单模型的时候,就会将训练的能力分散,这样就不能对某一区域的数据进行加强训练litian2008-10-31 21:12:22能不能给个例子litian2008-10-31 21:13:24把你自己做的东西拿出来大家看看啊litian2008-10-31 21:15:40放到论坛上,方便大家下载看看啊jungle192008-10-31 21:15:48支持向量机的模型在网上有很多,很多人提出的一个问题就是他的参数应该如何调整,支持向量机的参数不外乎三个:惩罚系数,偏差,核参数,其中惩罚系数和核参数并没有具体的范围限制,偏差不能太大,太大的话训练和测试的误差就较大,偏差设置过小很容易产生过拟合,一般偏差取0.01就可以了jungle192008-10-31 21:16:16例子过几天我整理好了放到论坛上litian2008-10-31 21:16:54那我问下,你那三个参数一般是怎么确定的jungle192008-10-31 21:18:19剩下的两个参数一般我用的是网格法jungle192008-10-31 21:21:33参数的选择现还没有什么好的办法,只能是搜索,如果,能从你数据的特征中找出这两个参数的关系,那将会减少很多的工作量,这也是我目前研究的内容,还在进一步的思考中支持向量机基本问题和研究热点支持向量机常见问题1. 支持向量机的关键技术是什么?答: 支持向量机性能的优劣主要取决于核函数的选取,所以对于一个实际问题而言,如何根据实际的数据模型选择合适的核函数从而构造SVM算法.目前比较成熟的核函数及其参数的选择都是人为的,根据经验来选取的,带有一定的随意性.在不同的问题领域,核函数应当具有不同的形式和参数,所以在选取时候应该将领域知识引入进来,但是目前还没有好的方法来解决核函数的选取问题.2. 支持向量机的优缺点?答:优点:SVM理论提供了一种避开高维空间的复杂性,直接用此空间的内积函数(既是核函数),再利用在线性可分的情况下的求解方法直接求解对应的高维空间的决策问题.当核函数已知,可以简化高维空间问题的求解难度.同时SVM是基于小样本统计理论的基础上的,这符合机器学习的目的.而且支持向量机比神经网络具有较好的泛化推广能力. 缺点:对于每个高维空间在此空间的映射F,如何确定F也就是核函数,现在还没有合适的方法,所以对于一般的问题,SVM只是把高维空间的复杂性的困难转为了求核函数的困难.而且即使确定核函数以后,在求解问题分类时,要求解函数的二次规划,这就需要大量的存储空间.这也是SVM的一个问题.3. 支持向量机的主要应用和研究的热点?答:目前支持向量机主要应用在模式识别领域中的文本识别,中文分类,人脸识别等;同时也应用到许多的工程技术和信息过滤等方面.当前研究的热点主要是对支持向量机中算法的优化,包括解决SVM中二次规划求解问题,对大规模SVM的求解问题,对SVM中QP问题的求解问题等.另外就是如何更好的构造基于SVM的多类分类器,如何提高SVM的归纳能力和分类速度等.如何根据实际问题确定核函数也是一个重要的研究热点.svm基本原理1、基本原理 对于很多分类问题,例如最简单的,一个平面上的两类不同的点,如何将它用一条直线分开?在平面上我们可能无法实现,但是如果通过某种映射,将这些点映射到其它空间(比如说球面上等),我们有可能在另外一个空间中很容易找到这样一条所谓的“分隔线”,将这些点分开。SVM基本上就是这样的原理,但是SVM本身比较复杂,因为它不仅仅是应用于平面内点的分类问题。SVM的一般做法是:将所有待分类的点映射到“高维空间”,然后在高维空间中找到一个能将这些
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2025年度高校学生实习保密责任书
- 2025年大件货物运输合同模板及运输路线规划
- 2025彩钢房智能仓储解决方案合同
- 2025年度智慧城市区域承包运营管理合同
- 2025版地下空间打桩工程合同范本
- 2025版海绵城市铺装工程合作协议
- 2025二手挖机二手挖掘设备买卖合同示范文本
- 2025年太阳能照明系统维护与检修合同
- 2025房地产抵押贷款中介服务合同范本
- 2025年食品加工委托生产产业链整合合作协议
- 糖尿病患者围手术期麻醉管理
- 胃肠疾病预防与健康管理
- 2025年全国新高考英语II卷试题解析及复习备考策略(课件)
- 全球化背景下文化自信的传承与创新
- 合规监督概念课件
- 电力变压器智能数字孪生体的构建与展望
- 无锡金栢精密模具有限公司搬迁项目环评资料环境影响
- 放射防护监测原始记录表模板
- 2025-2030中国奶酪行业市场发展现状及竞争格局与投资前景研究报告
- 垫资过桥合同协议
- 规范化司法所模板
评论
0/150
提交评论