How to set up LIBSVM Matlab interface?
Asked Answered
P

3

5

I am having problem with implementing LibSVM to MATLAB. I am using MATLAB R2009a (I also have the latest version, R2012b, but I dont use that one) I downloaded LibSVM package, libsvm-3.14 to my Windows 7 PC, which MATLAB and OCTAVE interface come together.

I extracted the folder I downloaded. Which, below, you can see the printscreen of what the folder has in.enter image description here

Where should I put my libsvm-3.14 extracted folder ? Should I put it under "bin" folder of my MATLAB installed in the directory?

C:\Program Files\MATLAB\R2009a\bin

I did that, however, it didn't work out. I will be grateful if you help me clearly. I just read README file, but it's not clear to understand and there is no other instructions online on the internet.

Pinfold answered 19/12, 2012 at 13:59 Comment(0)
K
8

For the time being, it does not matter where you put that folder. You'll have to compile the Matlab-MEX files, from the source code that resides in the matlab subfolder of your extracted libsvm package.

Below, I will call the libsvm-3.14 (for example: C:\libsvm-3.14) extracted folder ROOT (so replace ROOT wilth C:\libsvm-3.14 below).

So, fire up Matlab and, then, at its command prompt, type:

cd ROOT
cd matlab
make

Now, in the ROOT/matlab folder, you should have obtained two MEX files (with the .mexw32 or .mexw64 extension). These are the files that you will use from now on. You can discard the rest, except those files (and, maybe, some other generated libraries).

According to the Makefile (that is ROOT/matlab/make.m), the MEX files are called svmtrain and svmpredic (+ the extension).

So, next step would be to create a subfolder called libsvm/ under your's Matlab/toolbox folder, copy the two MEX files therein and, then, add that libsvm/ folder to the Matlab Path (not the Path of your system, but of your Matlab installation).

Then, by typing:

svmtrain

and

svmpredict

you should have the help (usage) of these two functions.

Kell answered 19/12, 2012 at 14:23 Comment(9)
there's something I didn't understand. I downloaded libsvm-3.14 and extracted it to desktop, then I changed the name of my extracted folder "libsvm-3-14" to ROOT. But where should I copy this file? is it to "bin" folder under MATLAB directory? (sorry if it sounds silly, I am so strange to these terms)Pinfold
@MuratArat ROOT is the name that I use in my post to designate the libsvm-3-14 folder. You do not copy it anywhere, let it there, just replace in my post ROOT with the actual path towards that libsvm-3-14 folder (the absolute path). I will update my answer to make this clear.Kell
ok I understand what you mean. to make things easier (en-dash, point, whatsoever) I named my extracted files as ROOT, which was placed on desktop. I started MATLAB and on Command window, I wrote what you said. I got this error "Error using cd Cannot CD to ROOT (Name is nonexistent or not a directory)." so I do not know what to do now.Pinfold
I need to install it urgently. please help me. I can provide more information if you wish.Pinfold
@MuratArat My answer has all the needed information. Instead of "cd ROOT" you should type in at Matlab prompt something like "cd C:\path\towards\the\folder\on\my\Desktop\libsvm-3.14" (it depends on your path). Or, you could use Matlab's graphical menu to change the current directory to be the folder libsvm-3.14.Kell
Much obliged Mister! I appreciate it!Pinfold
You're welcome. Glad that you succeed it. I overlooked the fact that you might not have the required C/C++ compiler for generating MEX files installed, but I am glad that you identified it correctly.Kell
Actually, I had compilers in my computer, however, MATLAB did not recognize these except Lcc included in MATLAB, eventhough these compilers are supported by MATLAB R2012b. So, I downloaded Microsoft Visual Studio 2010, which is available at no charge, all again and re-installed, in case of any missing file. I rebooted the computer and wrote this "mex -setup" command. Thanks again!Pinfold
Notice that "help svmpredict" doesn't work.. It took me a while to figure that outBunt
P
4

With the aid of @axeoth, here is the solution. I followed instruction files in matlab subfolder of extracted libsvm package. I downloaded and installed Microsoft Visual Studio 2010 and wrote 'mex -setup' on command window of MATLAB to choose a suitable compiler for mex (I use MATLAB R2012b in 32-bit PC, so I found supported compilers in this link http://www.mathworks.com/support/compilers/R2012b/win64.html) After then, I followed @axeoth's instructions. I changed the name of the folder to ROOT and moved it to Documents/MATLAB. I started MATLAB and on command window, I wrote these below "one by one"

>> cd C:\Users\HUstat\Documents\MATLAB\ROOT\matlab
>> cd matlab
>> make

then I copied everything obtained in ROOT/matlab subfolder. I created a new folder named libsvm under MATLAB/toolbox folder and pasted everything there. and then, I added that libsvm/ folder to the Matlab Path by using "Set Path" button on MATLAB R2012b. After then I wrote "svmtrain" and "svmpredict" so I got the helps of these two commands.

Pinfold answered 21/12, 2012 at 8:27 Comment(0)
S
1

For those having major compiler problems I thought I'd leave some extra information on the subject of installing compilers. This was a frustrating problem I had an ended up contacted MATLAB for help. I would have commented in the above posts but I do not have enough "rep" so here it is:

I was unable to install Microsoft Windows SDK 7.1, whether via Microsoft Visual Studio 2010 or otherwise. I found out that this was because I had a certain version of Microsoft Visual installed (version 10.0.04... was the cause of the problem for me). The work around was to uninstall Visual, install SDK 7.1 independently and then re-install Visual after. The process is written up in greater detail in the link below:

http://www.mathworks.com/matlabcentral/answers/95039-why-does-the-sdk-7-1-installation-fail-with-an-installation-failed-message-on-my-windows-system

It may also be that you have the compiler installed but that it wasn't recognised until MATLAB "found" it. This happened to me after the re-install. To check if you have the correct compiler and "find" it run mex.getCompilerConfigurations('Any','Installed') to get a full list. Then do mex -setup using the SDK 7.1 choosing the C/C++ version over FORTRAN.

I know the question is answered already but hopefully this may help someone the same predicament I had.

Slippery answered 29/9, 2014 at 8:47 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.