How to get started with libsvm under 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.
How to get started with libsvm under 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.
Download and extract libsvm in a directory of your choosing, say C:\libsvm
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
Once you have selected a compiler, you need to compile the MEX-files:
>> cd('C:\libsvm\matlab')
>> make
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')
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)
-b
i.e. probability. The result is showing same prob distribution among 5 classes for all tests. –
Accessory 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.
So to summarize:
1- I think you need to create "libsvm" folder under "C:\Program Files\MATLAB\R2014b\toolbox\".
2- Then copy the *.mexw64 files from the "libsvm-3.21\windows" folder to the new folder.
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"
© 2022 - 2024 — McMap. All rights reserved.
README
file located in the extracted archive undermatlab
subfolder. You will need to compile the MEX-files, then add the folder to the MATLAB search path – Backbreakingmex.getCompilerConfigurations('Any','Installed')
to get a list of installed compilers that are recognized by MATLAB – Backbreakingwindows
sub-folder of the extracted archive, the files are named:*.mexw64
) – BackbreakingC:\libsvm
. Start by telling MATLAB where to find the library by running:addpath('C:\libsvm\windows')
to have the compiled MEX-files available in the search path. Now you can test the functions with something like:svmtrain(double(rand(10,1)>0.5),rand(10,5),'-c 1 -g 0.1')
– Backbreaking