定义核函数及相关参数

上传人:ji****72 文档编号:35816750 上传时间:2018-03-20 格式:DOC 页数:2 大小:58KB
返回 下载 相关 举报
定义核函数及相关参数_第1页
第1页 / 共2页
定义核函数及相关参数_第2页
第2页 / 共2页
亲,该文档总共2页,全部预览完了,如果喜欢就下载吧!
资源描述

《定义核函数及相关参数》由会员分享,可在线阅读,更多相关《定义核函数及相关参数(2页珍藏版)》请在金锄头文库上搜索。

1、定义核函数及相关参数C = 200; % 拉格朗日乘子上界ker = struct(type,linear); %ker = struct(type,ploy,degree,3,offset,1); %ker = struct(type,gauss,width,1); %ker = struct(type,tanh,gamma,1,offset,0);% ker - 核参数(结构体变量)% the following fields: % type - linear : k(x,y) = x*y % poly : k(x,y) = (x*y+c)d % gauss : k(x,y) = exp(

2、-0.5*(norm(x-y)/s)2) % tanh : k(x,y) = tanh(g*x*y+c) % degree - Degree d of polynomial kernel (positive scalar). % offset - Offset c of polynomial and tanh kernel (scalar, negative for tanh). % width - Width s of Gauss kernel (positive scalar). % gamma - Slope g of the tanh kernel (positive scalar).

3、% -% % 构造两类训练样本n = 50; randn(state,6); x1 = randn(2,n); y1 = ones(1,n); x2 = 5+randn(2,n); y2 = -ones(1,n);figure(1); plot(x1(1,:),x1(2,:),bx,x2(1,:),x2(2,:),k.); axis(-3 8 -3 8); title(C-SVC) hold on;X = x1,x2; % 训练样本,dn 的矩阵,n 为样本个数,d 为样本维数 Y = y1,y2; % 训练目标,1n 的矩阵,n 为样本个数,值为+1 或-1% -% % 训练支持向量机tic

4、svm = svmTrain(svc_c,X,Y,ker,C); svm=C_SVC_Train(X,Y,C,ker);t_train = toc% svm 支持向量机(结构体变量)% the following fields: % type - 支持向量机类型 svc_c,svc_nu,svm_one_class,svr_epsilon,svr_nu % ker - 核参数 % x - 训练样本,dn 的矩阵,n 为样本个数,d 为样本维数 % y - 训练目标,1n 的矩阵,n 为样本个数,值为+1 或-1 % a - 拉格朗日乘子,1n 的矩阵% -% % 寻找支持向量a = svm.a

5、; epsilon = 1e-8; % 如果小于此值则认为是 0 i_sv = find(abs(a)epsilon); % 支持向量下标plot(X(1,i_sv),X(2,i_sv),ro);% -% % 测试输出x1,x2 = meshgrid(-2:0.1:7,-2:0.1:7); rows,cols = size(x1); nt = rows*cols; % 测试样本数Xt = reshape(x1,1,nt);reshape(x2,1,nt);tic Yd = svmSim(svm,Xt); % 测试输出t_sim = tocYd = reshape(Yd,rows,cols); contour(x1,x2,Yd,0 0,m); % 分类面hold off;

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

最新文档


当前位置:首页 > 行业资料 > 其它行业文档

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