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. CUBRID学习笔记 33 net事务 cubrid教程示例

    conn.BeginTransaction(); string sql = "create table t(idx integer)"; using (CUBRIDCommand ...

  2. SQL——连接查询

    以mysql为例: 新建两张表table1和table2 CREATE TABLE `table1` ( `id` ) NOT NULL auto_increment, `name` ) defaul ...

  3. 关于Docker 常用命令

    Docker 常用命令 分类列一下常用的CLI命令 仓库相关 search/ pull / push / login etc. 例:docker pull ubuntu 从仓库下载ubuntuimag ...

  4. 《FLASH CC 2015 CANVAS 中文教程》——3、this关键字 入门

    注::如果你对 FLASH 这个软件操作不够熟悉,建议你可以先看看FLASH动画之类的书. :FLASH CC 在文中直接简称为CC. :以下所以文章中所说的快捷键 如果你按了不起作用,请检查是否有其 ...

  5. XAF应用开发教程(三)业务对象模型之引用类型与关联关系

    本节介绍信息系统开发中最常见的问题,引用关系,一对多关系,多对多关系. 以客户信息为例,客户通常需要客户分类,如VIP客户,普通客户,潜在客户.当然,我们可以定义枚举类型进行定义出这个类型,并在客户类 ...

  6. C#线程系列讲座(5):同步技术之Monitor

    在上一讲介绍了使用lock来实现线程之间的同步.实际上,这个lock是C#的一个障眼法,在C#编译器编译lock语句时,将其编译成了调用Monitor类.先看看下面的C#源代码: public sta ...

  7. SAP FI/CO凭证不一致的解决办法

    First, use program RKACOR20 to delete the incorrect CO documents. OKBA - Transfer FI Documents to CO ...

  8. 初学CDQ分治-NEU1702

    关于CDQ分治,首先需要明白分治的复杂度. T(n) = 2T(n/2)+O(kn), T(n) = O(knlogn) T(n) = 2T(n/2)+O(knlogn), T(n) = O(knlo ...

  9. Tuning 简介

    典型的不好的设计: 破坏了系统的可扩展性(韧性) Applications requiring significant concurrency management as user populatio ...

  10. LCD控制器与驱动器

    这回我再讲讲从 MCU 到 LCD 之间是怎样一个控制流程,即我们的位图数据是怎样显示到 LCD 上的.前面我们了解到 LCD 显示是用动态扫描的方式来实现的,每次显示一整行,在一帧里每行一次扫描一遍 ...