简体   繁体   English

如何在MATLAB中运行libsvm?

[英]How to run libsvm in MATLAB?

How to get started with libsvm under MATLAB? 如何在MATLAB下开始使用libsvm

I've downloaded the library, and extracted it in C:\\Program Files\\MATLAB\\R2012a\\toolbox\\ , but then I don't know how to use it in MATLAB. 我已经下载了库,并在C:\\Program Files\\MATLAB\\R2012a\\toolbox\\提取了它,但后来我不知道如何在MATLAB中使用它。

Download and extract libsvm in a directory of your choosing, say C:\\libsvm 在您选择的目录中下载并解压缩libsvm,比如说C:\\libsvm

As described in the C:\\libsvm\\matlab\\README file, first you have to make sure a supported C/C++ compiler is installed. C:\\libsvm\\matlab\\README文件中所述,首先必须确保安装了受支持的C / C ++编译器 Note that on 64-bit systems, you need the correct 64-bit version of the compiler (eg Windows SDK is needed for Visual Studio Express edition) 请注意,在64位系统上,您需要正确的64位版本的编译器(例如,Visual Studio Express版本需要Windows SDK)

>> mex -setup

Once you have selected a compiler, you need to compile the MEX-files: 选择编译器后,需要编译MEX文件:

>> cd('C:\libsvm\matlab')
>> make

Finally add the folder with the generated binaries to the MATLAB search path: 最后将包含生成的二进制文件的文件夹添加到MATLAB搜索路径:

>> addpath('C:\libsvm\matlab')

Test the library with a simple example (fake data): 使用一个简单的例子(假数据)测试库:

>> labels = double(rand(10,1)>0.5);
>> data = rand(10,5);
>> model = svmtrain(labels, data, '-s 0 -t 2 -c 1 -g 0.1')

Note that the current version of libsvm includes pre-compiled 64-bit MEX-files for Windows. 请注意,当前版本的libsvm包含用于Windows的预编译64位MEX文件。 The binaries are located in C:\\libsvm\\windows\\*.mexw64 (copy those to the matlab subfolder from above) 二进制文件位于C:\\libsvm\\windows\\*.mexw64 (从上面复制到matlab子文件夹)

For me I didn't need to recompile the libsvm files(it did cause some problems with the .net framwork and windows SDK) I only used the already compiled files and added them to a new folder by following the steps mentioned here minus the make step. 对我来说,我不需要重新编译libsvm文件(它确实导致了.net框架和Windows SDK的一些问题)我只使用已编译的文件并按照此处提到的步骤将它们添加到新文件夹中减去make步。

So to summarize: 总结一下:

1- I think you need to create "libsvm" folder under "C:\\Program Files\\MATLAB\\R2014b\\toolbox\\". 1-我认为您需要在“C:\\ Program Files \\ MATLAB \\ R2014b \\ toolbox \\”下创建“libsvm”文件夹。

2- Then copy the *.mexw64 files from the "libsvm-3.21\\windows" folder to the new folder. 2-然后将* .mexw64文件从“libsvm-3.21 \\ windows”文件夹复制到新文件夹。

3- finally add the libsvm folder you just created to matlab bath by clicking the set path button in home and adding the new folder with the path "C:\\Program Files\\MATLAB\\R2014b\\toolbox\\libsvm" 3-最后通过单击home中的set path按钮并添加路径为“C:\\ Program Files \\ MATLAB \\ R2014b \\ toolbox \\ libsvm”的新文件夹,将刚创建的libsvm文件夹添加到matlab bath中

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM