在Matlab中使用LibSVM

主要分以下几步:

1、设置path路径

在home工具栏中选择set path ->add with subfolders->加入libsvm-3.11文件夹的路径

我这里是matlab2013版的,然后保存退出。

2、选择编译器

在matlab命令栏中输入如下代码:

mex -setup

注意中间有一个空格后才是“-setup"

出现如下代码:

Welcome to mex -setup.  This utility will help you set up  
a default compiler.  For a list of supported compilers, see  
http://www.mathworks.com/support/compilers/R2013a/win64.html 
 
Please choose your compiler for building MEX-files: 
 
Would you like mex to locate installed compilers [y]/n? y

这里是编译器选择,输入y,选择本地的编译器,然后确认所选择的编译器和路径就好了

Select a compiler: 
[1] Microsoft Visual C++ 2010 in D:\Program Files (x86)\Microsoft Visual Studio 10.0 
 
[0] None 
 
Compiler: 1
 
Please verify your choices: 
 
Compiler: Microsoft Visual C++ 2010  
Location: D:\Program Files (x86)\Microsoft Visual Studio 10.0 
 
Are these correct [y]/n? y

3、在matlab中编译

在matlab命令栏中输入:(注意当前文件夹要切换到libsvm->matlab文件夹下)

make

然后文件夹下每一个C文件都会出现一个对应的m或者mexw64文件(我是64位系统的)

到这一步如果没有报错的话说明 libsvm-mat 工具箱安装成功了。

4、加载数据集

这一步就是check一下是否可以用

按照教程上说的,输入代码

load heart_scale;

这里会报错,原因是文件夹下有两个数据集,一个是C++的, 一个是matlab的。libsvm库中下载的是C++数据,所以matlab加载我们下载的heart_scale是会报错的。解决办法如下:

输入代码换成:

libsvmread('heart_scale');  

工作空间中出现heart_scale_inst 和 heart_scale_label,说明加载成功了。

输入如下代码:

model = svmtrain(heart_scale_label,heart_scale_inst);
[predict_label,accuracy] = svmpredict(heart_scale_label,heart_scale_inst,model);

可以看到 结果

optimization finished, #iter = 162
nu = 0.431029
obj = -100.877288, rho = 0.424462
nSV = 132, nBSV = 107
Total nSV = 132
Accuracy = 86.6667% (234/270) (classification)

详细步骤参考 这里
数据集下载

libsvm库下载






评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值