详细步骤如下:
我的matlab版本 R2012a,我的libsvm版本3.16,系统版本是win7 64位
此时需注意,libsvm 3.12中提供的是c++版本的数据集heart_scale,这里需要加载matlab版本的数据集。
这两个数据集有什么不同呢?
C++版本的数据集里面如果某一个样本的某一个特征为0,这个特征可以不写在数据集中,但是在matlab版本中,必须要写出来。
否则的话,会报错
此时你可以选择下载matlab型的数据集,给一个链接。
http://download.csdn.net/detail/boruoshui/4881338
然后读取数据集
load heart_scale;
完成该步骤后发现Workspace中出现了heart_scale_inst 和 heart_scale_label,说明正确。
1.下载libsvm
http://www.csie.ntu.edu.tw/~cjlin/libsvm/我的matlab版本 R2012a,我的libsvm版本3.16,系统版本是win7 64位
2.解压至指定目录
将libsvm解压至D:\Program Files\MATLAB\R2012a\toolbox下,你也可以解压至你喜欢的地方。3.设置路径
file->set path
file-->Preferences-->general-->勾选 Enable toolbox path cache,然后点击 Update toolbox path cache
这步很重要!!否者出现 Undefined function or variable 'XXX' 等报错。
4.编译libsvm
首先在matlab设置当前目录为
在matlab命令窗口中输入
mex -setup
输入y
需要你选择编译器
再次确认自己的选择,输入y
编译器选择好了之后,用make.m编译
命令窗口输入make
可以看到新编译出4个文件libsvmread.mexw64,libsvmwrite.mexw64,svmtrain.mexw64,svmpredict.mexw64
在命令窗口中输入
load heart_scale;
此时需注意,libsvm 3.12中提供的是c++版本的数据集heart_scale,这里需要加载matlab版本的数据集。
这两个数据集有什么不同呢?
C++版本的数据集里面如果某一个样本的某一个特征为0,这个特征可以不写在数据集中,但是在matlab版本中,必须要写出来。
否则的话,会报错
http://download.csdn.net/detail/boruoshui/4881338
然后读取数据集
load heart_scale;
完成该步骤后发现Workspace中出现了heart_scale_inst 和 heart_scale_label,说明正确。
5 测试
model=svmtrain(heart_scale_label,heart_scale_inst);
[predict_lebel,accuracy]=svmpredict(heart_scale_label,heart_scale_inst,model);
说明安装正确,可以进行下一步实验。