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

  1. 提高开发效率的 Eclipse 实用操作

    工欲善其事,必先利其器.对于程序员来说,Eclipse便是其中的一个“器”.本文会从Eclipse快捷键和实用技巧这两个篇章展开介绍.Eclipse快捷键用熟后,不用鼠标,便可进行编程开发,避免鼠标分 ...

  2. Chrome 开发者工具实用操作

    Chrome 开发者工具实用操作 https://umaar.com/dev-tips/

  3. KiCAD实用操作

    KiCAD实用操作之一:自动编辑线宽 今天偶然间发现的一个比较实用的功能,算是KiCAD的一个优点吧(或许是在AD上面没发现):当整个PCB布完线或者在布线过程中,我们有可能需要对某个线的宽度进行调整 ...

  4. (原)Matlab的svmtrain和svmclassify

    转载请注明出处: http://www.cnblogs.com/darkknightzh/p/5554551.html 参考网址: http://www.cnblogs.com/zhangchaoya ...

  5. 能够提高开发效率的Eclipse实用操作

    工欲善其事,必先利其器.对于程序员来说,Eclipse便是其中的一个“器”.本文会从Eclipse快捷键和实用技巧这两个篇章展开介绍.Eclipse快捷键用熟后,不用鼠标,便可进行编程开发,避免鼠标分 ...

  6. 能够提高开发效率的 Eclipse 实用操作

    工欲善其事,必先利其器.对于程序员来说,Eclipse便是其中的一个“器”.本文会从Eclipse快捷键和实用技巧这两个篇章展开介绍.Eclipse快捷键用熟后,不用鼠标,便可进行编程开发,避免鼠标分 ...

  7. VS2019 实用操作

    本文列出了在编写程序过程中的几个非常实用的操作方式,通过这些操作方式,可以在一定程度上减少重复操作.提高编码效率.改善编程体验. 列模式操作 列操作是一项很常用且实用的功能,可以一次性修改不同的行. ...

  8. Netcat实用操作

    写久了web倦了,第n次开始尝试网络开发,于是熟悉一下常用工具. 尝试了一下netcat来测试服务器,或者充当客户端都异常好用.于是记录一下常用的一下命令 1. 充当服务器,或者客户端进行访问 通过n ...

  9. Myeclipse学习总结(8)——Eclipse实用操作

    工欲善其事,必先利其器.对于程序员来说,Eclipse便是其中的一个"器".本文会从Eclipse快捷键和实用技巧这两个篇章展开介绍.Eclipse快捷键用熟后,不用鼠标,便可进行 ...

随机推荐

  1. Struts2 和 spring mvc的 迭代标签常用属性对比

    <s:iterator value="#users" var="u" status="st"> <c:forEach  i ...

  2. git——学习笔记(三)分支管理

    一.创建.合并分支 每次提交,git都往后走一格,串成一跳时间线,head指向的是分支,分支指向提交.master是主分支,dev是另一条分支,分支就像指针一样,合并.删除分支时,修改的都是指针,工作 ...

  3. Deployment failed due to an error in FastDev assembly synchronization.

    在编译的时候发生Assembly synchronization error,显示信息为:Deployment failed due to an error in FastDev assembly s ...

  4. 《用格式化(fprintf和fscanf函数)的方式读写文件》

    //用格式化(fprintf和fscanf函数)的方式读写文件 [用格式化的方式向文件中写入数据]#include<stdio.h>#include<stdlib.h> int ...

  5. shell脚本入门教程(转)

    http://bbs.chinaunix.net/thread-391751-1-1.html http://www.cnblogs.com/suyang/archive/2008/05/18/120 ...

  6. 显示ios设备信息的程序

    以下是运行在本人iphone4上的截图,支持中文简体,中文繁体,英文,支持iphone和ipad,当然由于没有ipad,ipad的测试用的模拟器.支持iphone4的Retina屏幕.本来有6个标签, ...

  7. 网络图片下载缓存库SDWebImage的使用

    SDWebImage导入问题 最新的SDWebImage由于是基于ARC模式写的,如果创建的是非ARC醒目的童鞋们注意,导入文件夹之后,先添加ImageIO.framework,mapKit.fram ...

  8. BZOJ 1630/2023 Ant Counting 数蚂蚁

    DP. #include<iostream> #include<cstdio> #include<cstring> #include<algorithm> ...

  9. 多态-II(接口实现)

    <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...

  10. Cocos2d-x 3.x项目创建

    1.首先打开终端,cd到cocos2d-x-3.2目录下,运行命令./setup.py 2. 首先,打开终端cd到目录/cocos2d-x-3.2/tools/cocos2d-console/bin下 ...