安装libsvm工具包

来源:互联网 发布:网易云课堂网络 编辑:程序博客网 时间:2024/06/07 01:23

安装libsvm工具包步骤

一、进入官网主页下载工具包:

http://www.csie.ntu.edu.tw/~cjlin/libsvm/


二、解压文件,生成一个文件夹,我的是libsvm-3.21


三、设置路径,将libsvm-3.21文件夹添加到matlab搜索路径上。


       左上角File->Set Path->Add Folder->选中第二部解压生成的文件夹->Save


四、将Current Folder的路径指向第二部生成的文件夹:E:\libsvm-3.21\matlab\(我将工具包解压到了E盘的libsvm-3.21文件夹,实际操作时指向这个文件就可以了)


五、编译

再Matlab命令行输入mex -setup(注意中间的空格),出现如下提示:

 mex -setupPlease choose your compiler for building external interface (MEX) files:  Would you like mex to locate installed compilers [y]/n? y Select a compiler: [1] Microsoft Visual C++ 2010 in C:\Program Files (x86)\Microsoft Visual Studio 10.0  [0] None 

然后选择编译器:我电脑里只有这一个,所以就选择1。出现下面提示:让确认选择的编译器是否正确,如果正确就输入y

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

输入y之后,出现如下提示:

Are these correct [y]/n? y ***************************************************************************   Warning: MEX-files generated using Microsoft Visual C++ 2010 require            that Microsoft Visual Studio 2010 run-time libraries be             available on the computer they are run on.            If you plan to redistribute your MEX-files to other MATLAB            users, be sure that they have the run-time libraries. ***************************************************************************  Trying to update options file: C:\Users\wangxuewei\AppData\Roaming\MathWorks\MATLAB\R2010b\mexopts.bat From template:              C:\PROGRA~1\MATLAB\R2010b\bin\win64\mexopts\msvc100opts.bat  Done . . . 


六、make

在命令窗口输入:make

make如果成功了,会发现在Current Folder窗口中会多出四个后缀为.mexw64文件,这是编译后生成的。

七、测试

>>  [label_vector, instance_matrix] = libsvmread('E:\libsvm-3.21\heart_scale');>>  model=svmtrain(label_vector,instance_matrix);

其中 libsvmread('filename');是导入测试数据,在解压生成的文件夹libsvm-3.21,有一个名为heart_scale的文件,这里面包含测试数据,所以filename用指向heart_scale的路径代替就好。如果安装正确,运行结果如下:

*optimization finished, #iter = 162nu = 0.431029obj = -100.877288, rho = 0.424462nSV = 132, nBSV = 107Total nSV = 132


参考博客:http://blog.sciencenet.cn/blog-261330-627680.html






0 0