SVMtoy
SVMtoy
[label_matrix, instance_matrix] = libsvmread('ex8b.txt');
options = '';
% contour_level = [-1 0 1];
contour_level = [-0.2 0.2 1 2];
% function svmtoy(label_matrix, instance_matrix, options, contour_level)
%% svmtoy(label_matrix, instance_matrix, options, contour_level)
%% label_matrix: N by 1, has to be two-class
%% instance_matrix: N by 2
%% options: default '',
%% see libsvm-mat-8 README, has to be a classification formulation.
%% contour_level: default [0 0],
%% change to [-1 0 1] for showing the +/- 1 margin.
%%
%% svmtoy shows the two-class classification boundary of the 2-D data
%% based on libsvm-mat-2.8
%%
%% Hsuan-Tien Lin, htlin at caltech.edu, 2006/04/07
% if nargin <= 1
% instance_matrix = [];
% elseif nargin == 2
% options = ''
% end
%
% if nargin <= 3
% contour_level = [-1 0 1];
% end
N = size(label_matrix, 1);
if N <= 0
fprintf(2, 'number of data should be positive\n');
return;
end
if size(label_matrix, 2) ~= 1
fprintf(2, 'the label matrix should have only one column\n');
return;
end
if size(instance_matrix, 1) ~= N
fprintf(2, ['the label and instance matrices should have the same ' ...
'number of rows\n']);
return;
end
if size(instance_matrix, 2) ~= 2
fprintf(2, 'svmtoy only works for 2-D data\n');
return;
end
mdl = svmtrain(label_matrix, instance_matrix, options);
nclass = mdl.nr_class;
svmtype = mdl.Parameters(1);
if nclass ~= 2 || svmtype >= 2
fprintf(2, ['cannot plot the decision boundary for these ' ...
'SVM problems\n']);
return
end
minX = min(instance_matrix(:, 1));
maxX = max(instance_matrix(:, 1));
minY = min(instance_matrix(:, 2));
maxY = max(instance_matrix(:, 2));
gridX = (maxX - minX) ./ 100;
gridY = (maxY - minY) ./ 100;
minX = minX - 10 * gridX;
maxX = maxX + 10 * gridX;
minY = minY - 10 * gridY;
maxY = maxY + 10 * gridY;
[bigX, bigY] = meshgrid(minX:gridX:maxX, minY:gridY:maxY);
mdl.Parameters(1) = 3; % the trick to get the decision values
ntest=size(bigX, 1) * size(bigX, 2);
instance_test=[reshape(bigX, ntest, 1), reshape(bigY, ntest, 1)];
label_test = zeros(size(instance_test, 1), 1);
[Z]= svmpredict(label_test, instance_test, mdl);
bigZ = reshape(Z, size(bigX, 1), size(bigX, 2));
clf;
hold on;
ispos = (label_matrix == label_matrix(1));
pos = find(ispos);
neg = find(~ispos);
plot(instance_matrix(pos, 1), instance_matrix(pos, 2), 'o');
plot(instance_matrix(neg, 1), instance_matrix(neg, 2), 'x');
contour(bigX, bigY, bigZ, contour_level);
title(options);
SVMtoy的更多相关文章
- libsvm下的windows版本中的工具的使用
下载的libsvm包里面已经为我们编译好了(windows).进入libsvm\windows,可以看到这几个exe文件: a.svm-toy.exe:图形界面,可以自己画点,产生数据等. b.svm ...
- svm使用的一般步骤
LIBSVM 使用的一般步骤是:1)准备数据集,转化为 LIBSVM支持的数据格式 :[label] [index1]:[value1] [index2]:[value2] ...即 [l类别标号] ...
- libsvm简介和函数调用参数说明
1. libSVM简介 libSVM是台湾林智仁(Chih-Jen Lin) 教授2001年开发的一套支持向量机库,这套库运算速度挺快,可以很方便的对数据做分类或回归.由于libSVM程序小 ...
- libsvm使用详细说明
一,简介 LibSVM是台湾林智仁(Chih-Jen Lin)教授2001年开发的一套支持向量机的库,这套库运算速度还是挺快的,因此成为目前国内应用最多的SVM的库.详细的使用说明及博主博客见下链接: ...
- libsvm
代码文件主要针对Matlab进行说明,但个人仍觉得讲解的支持向量机内容非常棒,可以做为理解这一统计方法的辅助资料; LibSVM是台湾林智仁(Chih-Jen Lin)教授2001年开发的一套支持向量 ...
- libsvm-3.21使用文档
Libsvm is a simple, easy-to-use, and efficient software for SVM classification and regression. (可用于分 ...
- LibSVM使用指南
LibSVM使用指南 一. SVM简介 在进行下面的内容时我们认为你已经具备了数据挖掘的基础知识. SVM是新近出现的强大的数据挖掘工具,它在文本分类.手写文字识别.图像分类.生物序列分析等实 ...
- libsvm使用方法总结
1.所需要软件下载: (1)libsvm(http://www.csie.ntu.edu.tw/~cjlin/libsvm/) (2)python (3)gnuplot 画图软件(ftp://ftp. ...
- 使用libsvm对MNIST数据集进行实验
使用libsvm对MNIST数据集进行实验 在学SVM中的实验环节,老师介绍了libsvm的使用.当时看完之后感觉简单的说不出话来. 1. libsvm介绍 虽然原理要求很高的数学知识等,但是libs ...
随机推荐
- Intellij IDEA中使用Struts2
据说struts2中有很多的漏洞, 不过作为学习我也就用了吧, 因为书上面是按着这个讲的呀. 难怪官网上也没有struts2.2.1的版本的下载. 1. 下载struts2.2.1 ga版本 2. 新 ...
- ajax请求、servlet返回json数据
ajax请求.servlet返回json数据 1.方式一 response.setcontenttype("text/html;charset=utf-8"); response. ...
- LIST动态表格画线(动态列)
声明:原创作品,转载时请注明文章来自SAP师太技术博客( 博/客/园www.cnblogs.com):www.cnblogs.com/jiangzhengjun,并以超链接形式标明文章原始出处,否则将 ...
- [JAVA设计模式]第二部分:创建模式
声明:原创作品,转载时请注明文章来自SAP师太技术博客( 博/客/园www.cnblogs.com):www.cnblogs.com/jiangzhengjun,并以超链接形式标明文章原始出处,否则将 ...
- C library function - tmpfile()
Description The C library function FILE *tmpfile(void) creates a temporary file in binary update mod ...
- python_way day16 JQuary
python_way day16 JQuery 封装dom js代码 jQuery(1.10,1.12-兼容性好,2.0.以后放弃了ie9以下) - 封装了Dom & JavaScript 查 ...
- Doragon Kuesuto 1.15
#include<stdio.h> #include<stdlib.h> #include<time.h> int main() { ; ; ; int actio ...
- BUAA & ICT 夏令营之旅
我还只有二十几岁,总应该相信点什么吧. ================================ 7.10午后坐火车赶到北京.一路上火车行驶在茫茫云海里.车窗外的世界是这样子的:一片广袤的原野 ...
- Matlab中的persistent变量
persistent, 用于定义persistent变量.persistent变量对于声明它的函数来说是局部的,但是当退出该函数时,该变量仍然保存在内存中,数值并不变.persistent变量与全局变 ...
- Android 摇一摇之双甩功能
Android 摇一摇之双甩功能 最近做一个摇一摇的功能 网上相关代码很多 但是这次的需求有点奇葩 要求是摇两次才生效 看起来好像很简单 但真正要做遇到的问题还是很多 时间限制 机型灵敏性 摇动的方式 ...