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 ...
随机推荐
- C# WPF – 利用“Attached Property” 把 RoutedEvent 接上 ICommand
本文说明怎样把 DoubleClick 连接至 ICommand.方法很多.推荐使用 Attach Property 方式,因为它能把任何 RoutedEvent 接上任何 ICommand. 之前写 ...
- Metasploit辅助模块
msf > show auxiliary Auxiliary ========= Name Di ...
- 从xubuntu-->windows xp
捣鼓了两个月的ubuntu之后我又乖乖的回到了windows的怀抱,不是抛弃linux而是要适应身边的环境. 身边的板子的驱动基本上都是xp的老一点的还是vista的,让人情何以堪. 我努力克服了,用 ...
- SynchronizationContext的研究之一(非WPF及Forms)
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...
- 容易混淆的url src href
新手刚学习的时候会分不清 url src href这些,不知道什么情况下应该用哪个.现在让我来理一理. url 统一资源定位符是对可以从互联网上得到的资源的位置和访问方法的一种简洁的表示,是互联网 ...
- Quick-Cocos2d-x v3.3 异步加载Spine方案 转
Quick-Cocos2d-x v3.3 异步加载Spine方案 浩月难求也与2015-03-25 15:06:3441 次阅读 背景 项目中使用了Quick-Cocos2d-x 3.3,由于Spin ...
- [转载] leveldb日知录
原文: http://www.cnblogs.com/haippy/archive/2011/12/04/2276064.html 对leveldb非常好的一篇学习总结文章 郑重声明:本篇博客是自己学 ...
- 开启所有PHP错误!无论在任何时候
开发的时候,会屏蔽所有错误,但是有时候排查太蛋疼, 下面代码粘贴到控制器头部,开所有错误! 不可阻挡 ini_set('display_errors','1'); restore_error_ha ...
- js控制只能输入数字
onkeyup=clearNoNum(this) function clearNoNum(obj) { obj.value = obj.value.replace(/[^\d.]/g," ...
- @requestBody注解的使用
1.@requestBody注解常用来处理content-type不是默认的application/x-www-form-urlcoded编码的内容,比如说:application/json或者是ap ...