SVMshow

% http://www.peteryu.ca/tutorials/matlab/visualize_decision_boundaries

% load RankData
% NumTrain =200; load RankData2 lambda = 20;
rho = 1;
c1 =10;
c2 =10;
epsilon = 0.2;
result=[]; ker = 'lin';
sigma = 1/50;
par = NonLinearDualSVORIM(X, y, c1, c2, epsilon, rho, ker, sigma); % set up the domain over which you want to visualize the decision
% boundary
xrange = [-5 5];
yrange = [-5 5];
% step size for how finely you want to visualize the decision boundary.
inc = 0.1;
% generate grid coordinates. this will be the basis of the decision
% boundary visualization.
[x1, x2] = meshgrid(xrange(1):inc:xrange(2), yrange(1):inc:yrange(2));
% size of the (x, y) image, which will also be the size of the
% decision boundary image that is used as the plot background.
image_size = size(x1) xy = [x1(:) x2(:)]; % make (x,y) pairs as a bunch of row vectors.
%xy = [reshape(x, image_size(1)*image_size(2),1) reshape(y, image_size(1)*image_size(2),1)] % loop through each class and calculate distance measure for each (x,y)
% from the class prototype. % calculate the city block distance between every (x,y) pair and
% the sample mean of the class.
% the sum is over the columns to produce a distance for each (x,y)
% pair.
d = [];
for k=1:max(y)
d(:,k) = decisionfun(xy, par, X,y,k,epsilon, ker,sigma)';
end
[~,idx] = min(abs(d),[],2) % reshape the idx (which contains the class label) into an image.
decisionmap = reshape(idx, image_size); figure; %show the image
imagesc(xrange,yrange,decisionmap);
hold on;
set(gca,'ydir','normal'); % colormap for the classes:
% class 1 = light red, 2 = light green, 3 = light blue
cmap = [1 0.8 0.8; 0.95 1 0.95; 0.9 0.9 1]
colormap(cmap); % label the axes.
xlabel('x1');
ylabel('x2'); imagesc(xrange,yrange,decisionmap); % plot the class training data. color = {'r.','go','b*','r.','go','b*'};
for i=1:max(y)
plot(X(y==i,1),X(y==i,2), color{i});
hold on
end
% include legend
legend('Class 1', 'Class 2', 'Class 3','Location','NorthOutside', ...
'Orientation', 'horizontal'); hold on;
set(gca,'ydir','normal');

  

SVMshow的更多相关文章

随机推荐

  1. GenericServlet,HttpServletRequest和HttpServletResponse

    最基本的是通过实现Servlet接口来编写Servlet类,这需要实现Servlet接口中定义的5个方法. 为了简化Servlet的编写,在javax.servlet包中提供了一个抽象类Generic ...

  2. servlet&jsp高级:第四部分

    声明:原创作品,转载时请注明文章来自SAP师太技术博客( 博/客/园www.cnblogs.com):www.cnblogs.com/jiangzhengjun,并以超链接形式标明文章原始出处,否则将 ...

  3. CUBRID学习笔记 41 sql语法之groupby 等

    cubrid的中sql查询语法groupby GROUP BY ... HAVING Clause 按dept_no分组 SELECT dept_no, avg(sales_amount) FROM ...

  4. SQL——存储过程实例 调用带参数的过程(成绩输出)

    create or replace procedure test_score(input in number,output out char) is begin then begin output : ...

  5. iOS : 静态库(.framework)合并

    如果写了一个Framework,根据Build时选择的机器类型,会分为模拟器Framework和真机Framework,两者是不能混用的. 此时可以通过配置一个Run Script,在Script中使 ...

  6. javascript权威指南笔记--javascript语言核心(四)

    对象: 通过引用(而非值)来操作对象: var obj = {"x":1,"y":2}; var copyObj = obj; copyObj.x = 5; c ...

  7. SQL SERVER赋权限

    --创建登录账户 use master GO EXEC sp_addlogin 'jacky', 'pwd' --EXEC sp_droplogin 'jacky' --删除登陆账户 use Test ...

  8. C#生成JSON数据

    protected void Page_Load(object sender, EventArgs e) { Response.Clear(); Response.ContentType = &quo ...

  9. SQL server数据类型、增删改查

    数据类型: 整数型:bigint.int.smallint.mediumint.tinyint 小数类型:decimal.numeric 浮点型:real.float.double 位型:bit 字符 ...

  10. [转载] 深入理解Linux修改hostname

    原文: http://www.cnblogs.com/kerrycode/p/3595724.html 当我觉得对Linux系统下修改hostname已经非常熟悉的时候,今天碰到了几个个问题,这几个问 ...