问题描述
如何在MATLAB下开始使用 libsvm ?
How to get started with libsvm under MATLAB?
我已经下载了库,并将其提取到C:\Program Files\MATLAB\R2012a\toolbox\
中,但是我不知道如何在MATLAB中使用它.
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.
推荐答案
下载libsvm并将其解压缩到您选择的目录中,例如C:\libsvm
Download and extract libsvm in a directory of your choosing, say C:\libsvm
如C:\libsvm\matlab\README
文件中所述,首先必须确保受支持的C/C ++编译器已安装.请注意,在64位系统上,您需要正确的64位版本的编译器(例如,Visual Studio Express版本需要Windows SDK)
As described in the C:\libsvm\matlab\README
file, first you have to make sure a supported C/C++ compiler is installed. Note that on 64-bit systems, you need the correct 64-bit version of the compiler (e.g. Windows SDK is needed for Visual Studio Express edition)
>> mex -setup
选择编译器后,需要编译MEX文件:
Once you have selected a compiler, you need to compile the MEX-files:
>> cd('C:\libsvm\matlab')
>> make
最后将包含生成的二进制文件的文件夹添加到MATLAB搜索路径:
Finally add the folder with the generated binaries to the MATLAB search path:
>> 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')
请注意,当前版本的libsvm包含针对Windows的预编译的64位MEX文件.二进制文件位于C:\libsvm\windows\*.mexw64
中(将它们从上方复制到matlab
子文件夹中)
Note that the current version of libsvm includes pre-compiled 64-bit MEX-files for Windows. The binaries are located in C:\libsvm\windows\*.mexw64
(copy those to the matlab
subfolder from above)
这篇关于如何在MATLAB中运行libsvm?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!