安装libsvm-mat(林智仁版)方法
安装libsvm-mat是在MATLAB平台下使用libsvm的前提,如果没有安装好也就无法使用,在MATLAB平台下安装libsvm-mat一般有以下几个大步骤:
Libsvm-mat林智仁先生的原始版本下载
libsvm-mat-2.91-1.zip
http://www.matlabsky.com/thread-9328-1-1.html
【说明:最新的版本为libsvm-mat-3.0-1.zip大家可以在这里下载http://www.csie.ntu.edu.tw/~cjlin/libsvm/最新版本的改动是将SVM的model structure移动到了svm.h里面,对于常规用户没有影响基本和以前的都一样,只是方便一些高级用户自己进行底层代码的修改】
Libsvm-mat faruto版本下载
libsvm-mat-2.89-3[FarutoUltimate3.0]
http://www.matlabsky.com/thread-9327-1-1.html
GUI版本下载【基于libsvm-mat-2.89-3[FarutoUltimate3.0]】
[原创]SVM_GUI_2.0[mcode][by_faruto]
http://www.matlabsky.com/forum-v... -fromuid-18677.html
step2:将libsvm-mat所在工具箱添加到matlab工作搜索目录,具体操作如下:
1. 将libsvm-mat所在文件夹目录添加到MATLAB工作搜索目录(File ——》 Set Path…——》 Add withSubfolders...)
这第一步很重要,如果没有将libsvm-mat所在文件夹目录正确的添加到MATLAB工作搜索目录,使用的时候就会出现??? Undefined function or variable 'XXX'.等等报错。
下面具体说说如何选择编译器。
1. mex -setup
Remark :注意 mex 后面要打一个空格然后是-setup。千万别忘记打一个空格,发现好多朋友在mex和-setup之间没有打空格!!
1. Pleasechoose your compiler for building external interface (MEX) files:
2.
3. Would you likemex to locate installed compilers [y]/n?
解释:这里问你是否locate本机安装的编译器,正规的选择y然后指定编译器即可,我们先来看一下选择y(选择n在后面说),好下面我们选择y。
1. Pleasechoose your compiler for building external interface (MEX) files:
2.
3. Would youlike mex to locate installed compilers [y]/n?y
4. Select acompiler:
5. [1]Lcc-win32 C 2.4.1 in D:\MATLAB~1\sys\lcc
6. [2]Microsoft Visual C++ 6.0 in D:\Microsoft Visual Studio
7.
8. [0] None
9.
10. Compiler:
然后你选择相应的编译器并确认即可:
1. Compiler: 2
2.
3. Pleaseverify your choices:
4.
5. Compiler:Microsoft Visual C++ 6.0
6. Location:D:\Microsoft Visual Studio
7.
8. Are thesecorrect [y]/n? y
9.
10. Trying toupdate options file: C:\Users\faruto\AppData\Roaming\MathWorks\MATLAB\R2009b\mexopts.bat
11. Fromtemplate: D:\MATLAB~1\bin\win32\mexopts\msvc60opts.bat
12.
13. Done . . .
1. Pleasechoose your compiler for building external interface (MEX) files:
2.
3. Would youlike mex to locate installed compilers [y]/n?
复制代码
这一步选择y后,可选择的编译器里面有没你已经安装的编译器,表示MATLAB可能没有识别记录你安装的编译器的名字和目录(有时候会发生这种情况),此时你应该重新输入 mex –setup后选择n手动进行编译器的设置:
1. mex -setup
2. Pleasechoose your compiler for building external interface (MEX) files:
3.
4. Would youlike mex to locate installed compilers [y]/n? n
5.
6. Select acompiler:
7. [1] IntelC++ 9.1 (with Microsoft Visual C++ 2005 SP1 linker)
8. [2] IntelVisual Fortran 10.1 (with Microsoft Visual C++ 2005 SP1 linker)
9. [3]Lcc-win32 C 2.4.1
10. [4]Microsoft Visual C++ 6.0
11. [5]Microsoft Visual C++ .NET 2003
12. [6]Microsoft Visual C++ 2005 SP1
13. [7]Microsoft Visual C++ 2008 Express
14. [8]Microsoft Visual C++ 2008 SP1
15. [9] OpenWATCOM C++
16.
17. [0] None
18.
19. Compiler: 4%选择的这个编译器一定是你本机安装了的,否则选择了也没有用
20.
21. Your machinehas a Microsoft Visual C++ compiler located at
22. D:\MicrosoftVisual Studio. Do you want to use this compiler [y]/n?
这样的话就可以手动选择你想要的编译器了,在
1. Your machinehas a Microsoft Visual C++ compiler located at
2. D:\MicrosoftVisual Studio. Do you want to use this compiler [y]/n?
这个确认步骤,如果你的编译器的确是安装在MATLAB给出的这个目录(我这里是D:\MicrosoftVisual Studio)那么选择y确认即可,如果不是说明MATLAB没有识别出安装的地方,选择n手动指定目录即可,比如选择n后的结果如下:
1. Compiler: 4
2.
3. Your machinehas a Microsoft Visual C++ compiler located at
4. D:\MicrosoftVisual Studio. Do you want to use this compiler [y]/n? n
5. Please enterthe location of your compiler: [C:\Program Files\Microsoft Visual Studio]
1. make
如果成功运行没有报错,到此就说明libsvm-mat工具箱成功安装了。Libsvm-mat工具箱中有自带的heart_scale.mat测试数据集,可以运行以下代码来check一下是否安装成功:
1. loadheart_scale;
2. model =svmtrain(heart_scale_label,heart_scale_inst);
3. [predict_label,accuracy]= svmpredict(heart_scale_label,heart_scale_inst,model);
如果出现下面这个结果,则说明肯定安装成功了:
1. Accuracy =86.6667% (234/270) (classification)
注:编译文件(make)这一步为神马要把MATLAB的当前目录[Current Folder]调整到libsvm-mat所在的文件夹呢?
答曰:因为这一步要运行libsvm-mat工具箱中的make.m文件,因为当你使用某一个函数的时候,MATLAB首先会从当前目录搜索调用该函数,为了防止其他位置也有类似名字的make.m函数,所以这一步要把MATLAB的当前目录[Current Folder]调整到libsvm-mat所在的文件夹,优先运行libsvm-mat文件夹下的make.m文件。
1. % Thismake.m is used under Windows
2.
3. mex -O -csvm.cpp
4. mex -O -csvm_model_matlab.c
5. mex -Osvmtrain.c svm.obj svm_model_matlab.obj
6. mex -O svmpredict.csvm.obj svm_model_matlab.obj
7. mex -Olibsvmread.c
8. mex -Olibsvmwrite.c
哦,对了,安装完libsvm-mat工具箱,有的小朋友想要用 helpsvmtain和 help svmpredict来查看这两个函数的帮助文件,非常杯具的告诉你:
1. 运行help svmtain在较新版本下得到的是MATLAB自带的svmtrain函数的帮助文件;
2. 运行help svmpredict会有如下报错svmpredict notfound.
复制代码
此帖原作者faruto