🌐
Vivian Website
csie.ntu.edu.tw › ~cjlin › libsvm
LIBSVM -- A Library for Support Vector Machines
Our goal is to help users from other fields to easily use SVM as a tool. LIBSVM provides a simple interface where users can easily link it with their own programs. Main features of LIBSVM include ... Python, R, MATLAB, Perl, Ruby, Weka, Common LISP, CLISP, Haskell, OCaml, LabVIEW, and PHP ...
Library for Support Vector Machines
LIBSVM and LIBLINEAR are two popular open source machine learning libraries, both developed at the National Taiwan University and both written in C++ though with a C API. LIBSVM implements the sequential … Wikipedia
Factsheet
Developers Chih-Chung Chang and Chih-Jen Lin
Stable release 3.3
/ August 11, 2022; 3 years ago (2022-08-11)
Written in Java, C++
Factsheet
Developers Chih-Chung Chang and Chih-Jen Lin
Stable release 3.3
/ August 11, 2022; 3 years ago (2022-08-11)
Written in Java, C++
🌐
MathWorks
mathworks.com › matlabcentral › answers › 47595-how-we-can-use-libsvm-in-matlab
How we can use libsvm in MATLAB - MATLAB Answers - MATLAB Central
September 7, 2012 - How we can use libsvm in MATLAB. Learn more about support vector machine, data classification, svm, libsvm
🌐
GitHub
github.com › cjlin1 › libsvm › blob › master › matlab › README
libsvm/matlab/README at master · cjlin1/libsvm
--- MATLAB/OCTAVE interface of LIBSVM --- ----------------------------------------- · Table of Contents · ================= · - Introduction · - Installation · - Usage · - Returned Model Structure · - Other Utilities · - Examples · - Additional Information ·
Author   cjlin1
🌐
MathWorks
mathworks.com › matlabcentral › answers › 144542-how-to-run-libsvm-on-matlab
How to run libsvm on matlab? - MATLAB Answers - MATLAB Central
August 3, 2014 - Add the svmtrain, svmpredict, libsvmwrite & libscmread .mex Files to your matlab path (probably you just put them in the working folder...)
🌐
Google Sites
sites.google.com › site › kittipat › libsvm_matlab
Kittipat's Homepage - libsvm for MATLAB
libsvm is a great tool for SVM as it is very easy to use and is documented well. The libsvm package webpage is maintained by Chih-Chung Chang and Chih-Jen Lin of NTU. The webpage can be found here. I made this tutorial as a reminder for myself when I need to use it again. All the credits go for
Top answer
1 of 2
30

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)

2 of 2
2

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"

🌐
GitHub
github.com › cjlin1 › libsvm › tree › master › matlab
libsvm/matlab at master · cjlin1/libsvm
------------------------------... Introduction ============ This tool provides a simple interface to LIBSVM, a library for support vector machines (http://www.csie.ntu.edu.tw/~cjlin/libsvm)....
Author   cjlin1
Top answer
1 of 3
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.

2 of 3
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.

Find elsewhere
🌐
GitHub
github.com › cjlin1 › libsvm
GitHub - cjlin1/libsvm: LIBSVM -- A Library for Support Vector Machines · GitHub
Libsvm is available at http://www.csie.ntu.edu.tw/~cjlin/libsvm Please read the COPYRIGHT file before using libsvm. Table of Contents ================= - Quick Start - Installation and Data Format - `svm-train' Usage - `svm-predict' Usage - `svm-scale' Usage - Tips on Practical Use - Examples - Precomputed Kernels - Library Usage - Java Version - Building Windows Binaries - Additional Tools: Sub-sampling, Parameter Selection, Format checking, etc. - MATLAB/OCTAVE Interface - Python Interface - Additional Information Quick Start =========== If you are new to SVM and if the data is not large, please go to `tools' directory and use easy.py after installation.
Starred by 4.7K users
Forked by 1.6K users
Languages   Java 21.8% | C++ 18.7% | HTML 17.9% | M4 13.9% | Python 13.5% | C 13.3%
Top answer
1 of 1
12

In libsvm package, in the file matlab/README, you can find the following examples:

Examples
========

Train and test on the provided data heart_scale:

matlab> [heart_scale_label, heart_scale_inst] = libsvmread('../heart_scale');
matlab> model = svmtrain(heart_scale_label, heart_scale_inst, '-c 1 -g 0.07');
matlab> [predict_label, accuracy, dec_values] = svmpredict(heart_scale_label, heart_scale_inst, model); % test the training data

For probability estimates, you need '-b 1' for training and testing:

matlab> [heart_scale_label, heart_scale_inst] = libsvmread('../heart_scale');
matlab> model = svmtrain(heart_scale_label, heart_scale_inst, '-c 1 -g 0.07 -b 1');
matlab> [heart_scale_label, heart_scale_inst] = libsvmread('../heart_scale');
matlab> [predict_label, accuracy, prob_estimates] = svmpredict(heart_scale_label, heart_scale_inst, model, '-b 1');

To use precomputed kernel, you must include sample serial number as
the first column of the training and testing data (assume your kernel
matrix is K, # of instances is n):

matlab> K1 = [(1:n)', K]; % include sample serial number as first column
matlab> model = svmtrain(label_vector, K1, '-t 4');
matlab> [predict_label, accuracy, dec_values] = svmpredict(label_vector, K1, model); % test the training data

We give the following detailed example by splitting heart_scale into
150 training and 120 testing data.  Constructing a linear kernel
matrix and then using the precomputed kernel gives exactly the same
testing error as using the LIBSVM built-in linear kernel.

matlab> [heart_scale_label, heart_scale_inst] = libsvmread('../heart_scale');
matlab>
matlab> % Split Data
matlab> train_data = heart_scale_inst(1:150,:);
matlab> train_label = heart_scale_label(1:150,:);
matlab> test_data = heart_scale_inst(151:270,:);
matlab> test_label = heart_scale_label(151:270,:);
matlab>
matlab> % Linear Kernel
matlab> model_linear = svmtrain(train_label, train_data, '-t 0');
matlab> [predict_label_L, accuracy_L, dec_values_L] = svmpredict(test_label, test_data, model_linear);
matlab>
matlab> % Precomputed Kernel
matlab> model_precomputed = svmtrain(train_label, [(1:150)', train_data*train_data'], '-t 4');
matlab> [predict_label_P, accuracy_P, dec_values_P] = svmpredict(test_label, [(1:120)', test_data*train_data'], model_precomputed);
matlab>
matlab> accuracy_L % Display the accuracy using linear kernel
matlab> accuracy_P % Display the accuracy using precomputed kernel

Note that for testing, you can put anything in the
testing_label_vector.  For more details of precomputed kernels, please
read the section ``Precomputed Kernels'' in the README of the LIBSVM
package.
🌐
MathWorks
mathworks.com › matlabcentral › answers › 411485-libsvm-matlab-function-trainsvm-deprecated-and-replaced-by-fitcsvm
LIBSVM: MATLAB function "trainsvm" deprecated and replaced by "fitcsvm" - MATLAB Answers - MATLAB Central
July 21, 2018 - As MATLAB ha depreciated "svmtrain" and replaced it by "fitcsvm", LIBSVM is giving error: % This is an example of using precomputed kernel % using Libsvm in MATLAB, where K is the precomput...
🌐
Vivian Website
csie.ntu.edu.tw › ~cjlin › libsvmtools
LIBSVM Tools
For LIBLINEAR users, please download the zip file (MATLAB and Python interfaces are included). You must store weights in a separated file and specify -W your_weight_file. This setting is different from earlier versions where weights are in the first column of training data. Training/testing sets are the same as those for standard LIBSVM...
🌐
GitHub
github.com › cjlin1 › libsvm › blob › master › matlab › svmtrain.c
libsvm/matlab/svmtrain.c at master · cjlin1/libsvm
// Interface function of matlab · // now assume prhs[0]: label prhs[1]: features · void mexFunction( int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[] ) { const char *error_msg; · // fix random seed to have same results for each run · // (for cross validation and probability estimation) srand(1); · if(nlhs > 1) { exit_with_help(); fake_answer(nlhs, plhs); return; } · // Transform the input Matrix to libsvm format ·
Author   cjlin1
🌐
MathWorks
mathworks.com › matlabcentral › answers › 319905-how-to-make-a-classification-using-libsvm
How to make a Classification using LibSVM - MATLAB Answers - MATLAB Central
January 11, 2017 - On matlab, we make a matrix (Matrix for learning), which contains two columns, four lines and which contain (15, 20; 16, 21;18, 22; 22, 24). And we made a matrix composed of a single column (label matrix), this matrix (1, 1, 2, 3). We execute learning SVM with SVMtrain from libSVM.
🌐
Quora
quora.com › How-do-I-run-LIBSVM-in-MATLAB
How to run LIBSVM in MATLAB - Quora
Answer: You can download the LIBSVM on it's homepage. LIBSVM -- A Library for Support Vector Machines The library was written in C. So you will have to use mex to compile it. You can check it in the README file.
🌐
MathWorks
mathworks.com › matlabcentral › answers › 64403-whats-the-difference-between-svm-and-libsvm
whats the difference between svm and libsvm? - MATLAB Answers - MATLAB Central
February 21, 2013 - LIBSVM implements the Sequential minimal optimization (SMO) algorithm for kernelized support vector machines (SVMs), supporting classification and regression · Sign in to comment.
🌐
Alivelearn
alivelearn.net
SVM (support vector machine) with libsvm – Xu Cui while(alive){learn;}
Hello Xu Cui, I have learned cross-validation to learn optimal values for c and gamma for radial basis function SVM using LIBSVM and the code available at LIBSVM site. But if i want to use the same code to obtain value of only C for a linear SVM it does not work.Some matrix dimension mismatch is the error message. Can you help in this regards. Tnx. @serra MATLAB has built in ‘svmtrain’ and ‘svmclassify’ functions…
🌐
Vivian Website
csie.ntu.edu.tw › ~cjlin › libsvm › faq.html
LIBSVM FAQ
It depends on your data format. A simple way is to use libsvmwrite in the libsvm matlab/octave interface. Take a CSV (comma-separated values) file in UCI machine learning repository as an example. We download SPECTF.train. Labels are in the first column.