SVMshow
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的更多相关文章
随机推荐
- [CF738D]Sea Battle(贪心)
题目链接:http://codeforces.com/contest/738/problem/D 题意:1*n的格子里有a条长为b的船.有一个人射了k发子弹都没打中船,现在问最少再打多少次一定能保证射 ...
- windows下安装zabbix_agents_2.2.0
下载与解压 下载zabbix_agents_2.2.0 http://www.zabbix.com/downloads/2.2.0/zabbix_agents_2.2.0.win.zip 解压到C盘下 ...
- 优秀的Markdown编辑器MarkdownPad2免费版使用全功能
MarkdownPad,一款不错的Markdown编辑器,本人一直在用,具备所有Markdown的基本语法外支持一些特别的扩展,比如表格等. MarkdownPad分为免费版和收费版,区别是免费版不支 ...
- css样式 浏览器的读取顺序
css样式 浏览器的读取顺序 例: tbody tr td{} 浏览器是先查找td,然后去找td tr,然后去找td tr tbody div p{}和div>p{}的区别 .div p{} 是 ...
- iOS - OC 与 Swift 互相操作
前言 在 Swift 语言中,我们可以使用 Objective-C.C 语言编写代码,我们可以导入任意用 Objective-C 写的 Cocoa 平台框架.Objective-C 框架或 C 类库. ...
- js自定义弹窗
<一>confirm弹窗 页面操作中常见需要确认操作. 例如:删除某条消息前需要确认是否删除. 页面中弹窗确认操作用到confirm消息对话框. JS代码 function del(){ ...
- js数组知识
js数组 shift:删除原数组第一项,并返回删除元素的值:如果数组为空则返回undefined var a = [1,2,3,4,5]; var b = a.shift(); //a:[2,3, ...
- (二)miller指导查看主控板寄存器操作
Welcome to Command Shell!Username:admin Password:***** ROS>en ROS# ROS# ROS# ROS# ROS#^ada ROS(ad ...
- 将spring管理的bean使用注解的方式注入到servlet中
Filter和Servlet中不能直接注解使用spring的bean,因为这两个都是servlet容器维护管理的,当然也有实现方法,如下: 1.创建一个AbstractServlet 抽象类,让你的所 ...
- spring+redis实现缓存
spring + redis 实现数据的缓存 1.实现目标 通过redis缓存数据.(目的不是加快查询的速度,而是减少数据库的负担) 2.所需jar包 注意:jdies和commons-pool两个j ...