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的更多相关文章

  1. libsvm下的windows版本中的工具的使用

    下载的libsvm包里面已经为我们编译好了(windows).进入libsvm\windows,可以看到这几个exe文件: a.svm-toy.exe:图形界面,可以自己画点,产生数据等. b.svm ...

  2. svm使用的一般步骤

    LIBSVM 使用的一般步骤是:1)准备数据集,转化为 LIBSVM支持的数据格式 :[label] [index1]:[value1] [index2]:[value2] ...即 [l类别标号] ...

  3. libsvm简介和函数调用参数说明

    1.      libSVM简介 libSVM是台湾林智仁(Chih-Jen Lin) 教授2001年开发的一套支持向量机库,这套库运算速度挺快,可以很方便的对数据做分类或回归.由于libSVM程序小 ...

  4. libsvm使用详细说明

    一,简介 LibSVM是台湾林智仁(Chih-Jen Lin)教授2001年开发的一套支持向量机的库,这套库运算速度还是挺快的,因此成为目前国内应用最多的SVM的库.详细的使用说明及博主博客见下链接: ...

  5. libsvm

    代码文件主要针对Matlab进行说明,但个人仍觉得讲解的支持向量机内容非常棒,可以做为理解这一统计方法的辅助资料; LibSVM是台湾林智仁(Chih-Jen Lin)教授2001年开发的一套支持向量 ...

  6. libsvm-3.21使用文档

    Libsvm is a simple, easy-to-use, and efficient software for SVM classification and regression. (可用于分 ...

  7. LibSVM使用指南

    LibSVM使用指南 一.     SVM简介 在进行下面的内容时我们认为你已经具备了数据挖掘的基础知识. SVM是新近出现的强大的数据挖掘工具,它在文本分类.手写文字识别.图像分类.生物序列分析等实 ...

  8. libsvm使用方法总结

    1.所需要软件下载: (1)libsvm(http://www.csie.ntu.edu.tw/~cjlin/libsvm/) (2)python (3)gnuplot 画图软件(ftp://ftp. ...

  9. 使用libsvm对MNIST数据集进行实验

    使用libsvm对MNIST数据集进行实验 在学SVM中的实验环节,老师介绍了libsvm的使用.当时看完之后感觉简单的说不出话来. 1. libsvm介绍 虽然原理要求很高的数学知识等,但是libs ...

随机推荐

  1. Timeout expired超时时间已到. 达到了最大池大小 错误及Max Pool Size设置

    此文章非原创,仅为分享.学习!!! 参考数据库链接串: <add key="data" value="server=192.168.1.123; port=3306 ...

  2. 字符串处理:ABAP中的正则表达式

    声明:原创作品,转载时请注明文章来自SAP师太技术博客( 博/客/园www.cnblogs.com):www.cnblogs.com/jiangzhengjun,并以超链接形式标明文章原始出处,否则将 ...

  3. Linux的查找命令

    1. 文件搜索find find是最常见和最强大的查找命令,你可以用它找到任何你想找的文件. find的使用格式如下: $ find [搜索路径] [搜索条件][搜索文件名] 如果什么参数也不加,fi ...

  4. hd1496---->这道题是水水的数论吗?

    题目:http://acm.hdu.edu.cn/showproblem.php?pid=1496 题意: Consider equations having the following form: ...

  5. Git与Repo入门(转载)

    aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAykAAADuCAIAAACyDd+sAAAAA3NCSVQICAjb4U/gAAAgAElEQVR4Xu ...

  6. 了解OpenStack

    OpenStack是一个由NASA(美国国家航空航天局)和Rackspace合作研发并发起的,以Apache许可证授权的自由软件和开放源代码项目. OpenStack支持几乎所有类型的云环境,项目目标 ...

  7. Xcode好用的插件

    注释:每当Xcode升级之后,都会导致原有的Xcode插件不能使用,这是因为每个插件的Info.plist中记录了该插件兼容Xcode版本的DVTPlugInCompatibilityUUID,而每个 ...

  8. Winform_ComBox三种赋值方式

    第一种方法: DataTable dt = new DataTable(); dt.Columns.Add( "name" ); dt.Columns.Add( "val ...

  9. Mvc4_MvcPager 概述

    MvcPager分页控件是在ASP.NET MVC Web应用程序中实现分页功能的一系列扩展方法,该分页控件的最初的实现方法借鉴了网上流行的部分源代码, 尤其是ScottGu的PagedList< ...

  10. JAVA获取当前系统时间System.currentTimeMillis()

    System.currentTimeMillis()产生一个当前的毫秒,这个毫秒其实就是自1970年1月1日0时起的毫秒数,Date()其实就是相当于Date(System.currentTimeMi ...