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. IP地址验证

    /** * 验证IP地址 * * @param 待验证的字符串 * @return 如果是符合格式的字符串,返回 <b>true </b>,否则为 <b>false ...

  2. mysql启动关闭

    RedHat Linux (Fedora Core/Cent OS) 1.启动:/etc/init.d/mysqld start2.停止:/etc/init.d/mysqld stop3.重启:/et ...

  3. loutsScript 常用代码

    1.FTSearch搜索: Set dc=db.Ftsearch("name",0) '0位置为最大的查询数,0为所有匹配的文件 FTSearch必须创建数据库索引 Set doc ...

  4. 49个jquery代码经典片段

    49个jquery代码经典片段,这些代码能够给你的javascript项目提供帮助.其中的一些代码段是从jQuery1.4.2才开始支持的做法,另一些则是真正有用的函数或方法,他们能够帮助你又快又好地 ...

  5. shell script针对参数已经有配置好变量名称

    /path/to/scriptname opt1 opt2 opt3 opt4 $ $ $ $ $ 这样够清楚了吧?运行的脚本档名为 $0 这个变量,第一个接的参数就是 $1 啊- 所以,只要我们在 ...

  6. 访问远程mysql数据库

    使用mysql命令窗口模式/工具,比如需要给'10.2.9.239' 的用户分配mantis123,mantis123访问,则使用如下格式: GRANT ALL PRIVILEGES ON *.* T ...

  7. 表单美化-原生javascript和jQuery多选按钮(兼容IE6)

    前些天我们讲了下单选按钮的美化今天来做表单元素多选按钮的美化.我们的想法是:利用多选按钮是否被选中和是否不给选择的特性来为按钮的父元素添加对应的样式,就是说用什么的样式是由按钮的状态来决定. 用到的图 ...

  8. c function

    /* #include<stdio.h> int is_prime(int n) { for(int i = 2; i <= n/2; i ++) if(n % 2 == 0) re ...

  9. Data truncated for column xxx

    对于字段XXX,数据发生截断.原因是:字段的取值,不满足约束条件.比如下面的情况: 原来的字段取值为null,现在约束字段not null,就会报错Data truncated for column ...

  10. hdu 4864 Task

    题目链接:hdu 4864 其实就是个贪心,只是当初我想的有偏差,贪心的思路不对,应该是这样子的: 因为 xi 的权值更重,所以优先按照 x 来排序,而这样的排序方式决定了在满足任务(即 xi > ...