SVM实用操作: svmtrain and svmclassify
load fisheriris
data = [meas(:,), meas(:,)];
groups = ismember(species,'setosa');
[train, test] = crossvalind('holdOut',groups);
cp = classperf(groups);
svmStruct = svmtrain(data(train,:),groups(train),'showplot',true); classes = svmclassify(svmStruct,data(test,:),'showplot',true);
classperf(cp,classes,test);

svmstruct = svmtrain(Training, Group)
Rows of TRAINING correspond to observations; columns correspond to features. Y is a column vector that contains the known class labels for TRAINING.
Y is a grouping variable, i.e., it can be a categorical, numeric, or logical vector; a cell vector of strings; or a character matrix with each row representing a
class label (see help for groupingvariable). Each element of Y specifies the group the corresponding row of TRAINING belongs to.
TRAINING and Y must have the same number of rows. SVMSTRUCT contains information about the trained classifier, including the support vectors, that
is used by SVMCLASSIFY for classification. svmtrain treats NaNs, empty strings or 'undefined' values as missing values and ignores the corresponding
rows in TRAINING and Y.
Group = svmclassify(SVMStruct, Sample)
>> help svmclassify
svmclassify Classify data using a support vector machine
GROUP = svmclassify(SVMSTRUCT, TEST) classifies each row in TEST using the support vector machine classifier structure SVMSTRUCT created
using SVMTRAIN, and returns the predicted class level GROUP. TEST must have the same number of columns as the data used to train the
classifier in SVMTRAIN. GROUP indicates the group to which each row of TEST is assigned.
GROUP = svmclassify(...,'SHOWPLOT',true) plots the test data TEST on the figure created using the SHOWPLOT option in SVMTRAIN.
-----------------------------------------------------------------------------------------------
-----------------------------------------------------------------------------------------------
利用libsvm做多分类问题的经典案例:
[y, x] = libsvmread('iris.scale.txt');
m = svmtrain(y, x, '-t 0');
test_y=[1;2;3];
test_x=[-0.555556 0.25 -0.864407 -0.916667;
0.444444 -0.0833334 0.322034 0.166667 ;
-0.277778 -0.333333 0.322034 0.583333 ];
[predict_label, accuracy, prob_estimates] = svmpredict(test_y, test_x, m);
数据:'iris.scale'可在Libsvm网站上有。共有三类。
iris.scale.txt 文档为: :-0.555556 :0.25 :-0.864407 :-0.916667
:-0.666667 :-0.166667 :-0.864407 :-0.916667
:-0.777778 :-0.898305 :-0.916667
:-0.833333 :-0.0833334 :-0.830508 :-0.916667
:-0.611111 :0.333333 :-0.864407 :-0.916667
:-0.388889 :0.583333 :-0.762712 :-0.75
:-0.833333 :0.166667 :-0.864407 :-0.833333
:-0.611111 :0.166667 :-0.830508 :-0.916667
:-0.944444 :-0.25 :-0.864407 :-0.916667
:-0.666667 :-0.0833334 :-0.830508 :-
:-0.388889 :0.416667 :-0.830508 :-0.916667
:-0.722222 :0.166667 :-0.79661 :-0.916667
:-0.722222 :-0.166667 :-0.864407 :-
:- :-0.166667 :-0.966102 :-
:-0.166667 :0.666667 :-0.932203 :-0.916667
:-0.222222 : :-0.830508 :-0.75
:-0.388889 :0.583333 :-0.898305 :-0.75
:-0.555556 :0.25 :-0.864407 :-0.833333
:-0.222222 :0.5 :-0.762712 :-0.833333
:-0.555556 :0.5 :-0.830508 :-0.833333
:-0.388889 :0.166667 :-0.762712 :-0.916667
:-0.555556 :0.416667 :-0.830508 :-0.75
:-0.833333 :0.333333 :- :-0.916667
:-0.555556 :0.0833333 :-0.762712 :-0.666667
:-0.722222 :0.166667 :-0.694915 :-0.916667
:-0.611111 :-0.166667 :-0.79661 :-0.916667
:-0.611111 :0.166667 :-0.79661 :-0.75
:-0.5 :0.25 :-0.830508 :-0.916667
:-0.5 :0.166667 :-0.864407 :-0.916667
:-0.777778 :-0.79661 :-0.916667
:-0.722222 :-0.0833334 :-0.79661 :-0.916667
:-0.388889 :0.166667 :-0.830508 :-0.75
:-0.5 :0.75 :-0.830508 :-
:-0.333333 :0.833333 :-0.864407 :-0.916667
:-0.666667 :-0.0833334 :-0.830508 :-
:-0.611111 :-0.932203 :-0.916667
:-0.333333 :0.25 :-0.898305 :-0.916667
:-0.666667 :-0.0833334 :-0.830508 :-
:-0.944444 :-0.166667 :-0.898305 :-0.916667
:-0.555556 :0.166667 :-0.830508 :-0.916667
:-0.611111 :0.25 :-0.898305 :-0.833333
:-0.888889 :-0.75 :-0.898305 :-0.833333
:-0.944444 :-0.898305 :-0.916667
:-0.611111 :0.25 :-0.79661 :-0.583333
:-0.555556 :0.5 :-0.694915 :-0.75
:-0.722222 :-0.166667 :-0.864407 :-0.833333
:-0.555556 :0.5 :-0.79661 :-0.916667
:-0.833333 :-0.864407 :-0.916667
:-0.444444 :0.416667 :-0.830508 :-0.916667
:-0.611111 :0.0833333 :-0.864407 :-0.916667
:0.5 :0.254237 :0.0833333
:0.166667 :0.186441 :0.166667
:0.444444 :-0.0833334 :0.322034 :0.166667
:-0.333333 :-0.75 :0.0169491 :-4.03573e-08
:0.222222 :-0.333333 :0.220339 :0.166667
:-0.222222 :-0.333333 :0.186441 :-4.03573e-08
:0.111111 :0.0833333 :0.254237 :0.25
:-0.666667 :-0.666667 :-0.220339 :-0.25
:0.277778 :-0.25 :0.220339 :-4.03573e-08
:-0.5 :-0.416667 :-0.0169491 :0.0833333
:-0.611111 :- :-0.152542 :-0.25
:-0.111111 :-0.166667 :0.0847457 :0.166667
:-0.0555556 :-0.833333 :0.0169491 :-0.25
:-1.32455e-07 :-0.25 :0.254237 :0.0833333
:-0.277778 :-0.25 :-0.118644 :-4.03573e-08
:0.333333 :-0.0833334 :0.152542 :0.0833333
:-0.277778 :-0.166667 :0.186441 :0.166667
:-0.166667 :-0.416667 :0.0508474 :-0.25
:0.0555554 :-0.833333 :0.186441 :0.166667
:-0.277778 :-0.583333 :-0.0169491 :-0.166667
:-0.111111 :0.288136 :0.416667
:-1.32455e-07 :-0.333333 :0.0169491 :-4.03573e-08
:0.111111 :-0.583333 :0.322034 :0.166667
:-1.32455e-07 :-0.333333 :0.254237 :-0.0833333
:0.166667 :-0.25 :0.118644 :-4.03573e-08
:0.277778 :-0.166667 :0.152542 :0.0833333
:0.388889 :-0.333333 :0.288136 :0.0833333
:0.333333 :-0.166667 :0.355932 :0.333333
:-0.0555556 :-0.25 :0.186441 :0.166667
:-0.222222 :-0.5 :-0.152542 :-0.25
:-0.333333 :-0.666667 :-0.0508475 :-0.166667
:-0.333333 :-0.666667 :-0.0847458 :-0.25
:-0.166667 :-0.416667 :-0.0169491 :-0.0833333
:-0.0555556 :-0.416667 :0.38983 :0.25
:-0.388889 :-0.166667 :0.186441 :0.166667
:-0.0555556 :0.166667 :0.186441 :0.25
:0.333333 :-0.0833334 :0.254237 :0.166667
:0.111111 :-0.75 :0.152542 :-4.03573e-08
:-0.277778 :-0.166667 :0.0508474 :-4.03573e-08
:-0.333333 :-0.583333 :0.0169491 :-4.03573e-08
:-0.333333 :-0.5 :0.152542 :-0.0833333
:-1.32455e-07 :-0.166667 :0.220339 :0.0833333
:-0.166667 :-0.5 :0.0169491 :-0.0833333
:-0.611111 :-0.75 :-0.220339 :-0.25
:-0.277778 :-0.416667 :0.0847457 :-4.03573e-08
:-0.222222 :-0.166667 :0.0847457 :-0.0833333
:-0.222222 :-0.25 :0.0847457 :-4.03573e-08
:0.0555554 :-0.25 :0.118644 :-4.03573e-08
:-0.555556 :-0.583333 :-0.322034 :-0.166667
:-0.222222 :-0.333333 :0.0508474 :-4.03573e-08
:0.111111 :0.0833333 :0.694915 :
:-0.166667 :-0.416667 :0.38983 :0.5
:0.555555 :-0.166667 :0.661017 :0.666667
:0.111111 :-0.25 :0.559322 :0.416667
:0.222222 :-0.166667 :0.627119 :0.75
:0.833333 :-0.166667 :0.898305 :0.666667
:-0.666667 :-0.583333 :0.186441 :0.333333
:0.666667 :-0.25 :0.79661 :0.416667
:0.333333 :-0.583333 :0.627119 :0.416667
:0.611111 :0.333333 :0.728813 :
:0.222222 :0.38983 :0.583333
:0.166667 :-0.416667 :0.457627 :0.5
:0.388889 :-0.166667 :0.525424 :0.666667
:-0.222222 :-0.583333 :0.355932 :0.583333
:-0.166667 :-0.333333 :0.38983 :0.916667
:0.166667 :0.457627 :0.833333
:0.222222 :-0.166667 :0.525424 :0.416667
:0.888889 :0.5 :0.932203 :0.75
:0.888889 :-0.5 : :0.833333
:-0.0555556 :-0.833333 :0.355932 :0.166667
:0.444444 :0.59322 :0.833333
:-0.277778 :-0.333333 :0.322034 :0.583333
:0.888889 :-0.333333 :0.932203 :0.583333
:0.111111 :-0.416667 :0.322034 :0.416667
:0.333333 :0.0833333 :0.59322 :0.666667
:0.611111 :0.694915 :0.416667
:0.0555554 :-0.333333 :0.288136 :0.416667
:-1.32455e-07 :-0.166667 :0.322034 :0.416667
:0.166667 :-0.333333 :0.559322 :0.666667
:0.611111 :-0.166667 :0.627119 :0.25
:0.722222 :-0.333333 :0.728813 :0.5
: :0.5 :0.830508 :0.583333
:0.166667 :-0.333333 :0.559322 :0.75
:0.111111 :-0.333333 :0.38983 :0.166667
:-1.32455e-07 :-0.5 :0.559322 :0.0833333
:0.888889 :-0.166667 :0.728813 :0.833333
:0.111111 :0.166667 :0.559322 :0.916667
:0.166667 :-0.0833334 :0.525424 :0.416667
:-0.0555556 :-0.166667 :0.288136 :0.416667
:0.444444 :-0.0833334 :0.491525 :0.666667
:0.333333 :-0.0833334 :0.559322 :0.916667
:0.444444 :-0.0833334 :0.38983 :0.833333
:-0.166667 :-0.416667 :0.38983 :0.5
:0.388889 :0.661017 :0.833333
:0.333333 :0.0833333 :0.59322 :
:0.333333 :-0.166667 :0.423729 :0.833333
:0.111111 :-0.583333 :0.355932 :0.5
:0.222222 :-0.166667 :0.423729 :0.583333
:0.0555554 :0.166667 :0.491525 :0.833333
:-0.111111 :-0.166667 :0.38983 :0.416667
SVM实用操作: svmtrain and svmclassify的更多相关文章
- 提高开发效率的 Eclipse 实用操作
工欲善其事,必先利其器.对于程序员来说,Eclipse便是其中的一个“器”.本文会从Eclipse快捷键和实用技巧这两个篇章展开介绍.Eclipse快捷键用熟后,不用鼠标,便可进行编程开发,避免鼠标分 ...
- Chrome 开发者工具实用操作
Chrome 开发者工具实用操作 https://umaar.com/dev-tips/
- KiCAD实用操作
KiCAD实用操作之一:自动编辑线宽 今天偶然间发现的一个比较实用的功能,算是KiCAD的一个优点吧(或许是在AD上面没发现):当整个PCB布完线或者在布线过程中,我们有可能需要对某个线的宽度进行调整 ...
- (原)Matlab的svmtrain和svmclassify
转载请注明出处: http://www.cnblogs.com/darkknightzh/p/5554551.html 参考网址: http://www.cnblogs.com/zhangchaoya ...
- 能够提高开发效率的Eclipse实用操作
工欲善其事,必先利其器.对于程序员来说,Eclipse便是其中的一个“器”.本文会从Eclipse快捷键和实用技巧这两个篇章展开介绍.Eclipse快捷键用熟后,不用鼠标,便可进行编程开发,避免鼠标分 ...
- 能够提高开发效率的 Eclipse 实用操作
工欲善其事,必先利其器.对于程序员来说,Eclipse便是其中的一个“器”.本文会从Eclipse快捷键和实用技巧这两个篇章展开介绍.Eclipse快捷键用熟后,不用鼠标,便可进行编程开发,避免鼠标分 ...
- VS2019 实用操作
本文列出了在编写程序过程中的几个非常实用的操作方式,通过这些操作方式,可以在一定程度上减少重复操作.提高编码效率.改善编程体验. 列模式操作 列操作是一项很常用且实用的功能,可以一次性修改不同的行. ...
- Netcat实用操作
写久了web倦了,第n次开始尝试网络开发,于是熟悉一下常用工具. 尝试了一下netcat来测试服务器,或者充当客户端都异常好用.于是记录一下常用的一下命令 1. 充当服务器,或者客户端进行访问 通过n ...
- Myeclipse学习总结(8)——Eclipse实用操作
工欲善其事,必先利其器.对于程序员来说,Eclipse便是其中的一个"器".本文会从Eclipse快捷键和实用技巧这两个篇章展开介绍.Eclipse快捷键用熟后,不用鼠标,便可进行 ...
随机推荐
- ios页面间传递参数四种方式
ios页面间传递参数四种方式 1.使用SharedApplication,定义一个变量来传递. 2.使用文件,或者NSUserdefault来传递 3.通过一个单例的class来传递 4.通过Dele ...
- 团队SCRUM会议(第一次)
每日Scrum:第一天 会议时间:4.30.晚八点半 会议地点:基础教学楼一楼大厅 小组成员:郭庆樑,林彦汝,张金 团队PM:张金 会议进程 • 首先我们讨论了实验第一个Sprint1要实现的功能,我 ...
- mysql 命令行操作
1.连接Mysql 格式: mysql -h主机地址 -u用户名 -p用户密码 1.连接到本机上的MYSQL.首先打开DOS窗口,然后进入目录mysql\bin,再键入命令mysql -u root ...
- C#导入EXCEL数据
public static void InputUserFromExcel(string filePath) { string FileExName = filePath.Substring(file ...
- 中国省市 JS代码
很实用的一段JS代码, 用户注册的时候,选择地址常用到.代码如下: <script language="javascript"> var g_selProvince; ...
- VS调试Ajax
VS调试Ajax: 1.ashx在后台处理程序中设定断点 2.触发AJAX 3.F12打开浏览器调试,搜索找到ajax调用的JS,设置断点,在浏览器中单步调试,会自动进入后台处理程序,然后就可以调试后 ...
- 【LeetCode】172. Factorial Trailing Zeroes
Factorial Trailing Zeroes Given an integer n, return the number of trailing zeroes in n!. Note: Your ...
- Java 集合深入理解(3):Collection
点击查看 Java 集合框架深入理解 系列, - ( ゜- ゜)つロ 乾杯~ 今天心情有点粉,来学学 Collection 吧! 什么是集合? 集合,或者叫容器,是一个包含多个元素的对象: 集合可以对 ...
- [转]Table-Driven and Data Driven Programming
What is Table-Driven and Data-Driven Programming? Data/Table-Driven programming is the technique of ...
- csdn第四名
编号:1027时间:2016年7月18日11:10:42功能:csdn第四名URL :http://blog.csdn.net/yuanmeng001