SVM Learning Notes (1) libsvm in MATLAB under the use of installation _ machine learning

Source: Internet
Author: User
Tags numeric value svm

1 from LIBSVM's official website http://www.csie.ntu.edu.tw/~cjlin/libsvm/Download the latest version of the LIBSVM, the current version of the Libsvm-3.16.zip

2 decompression and compression package to the computer on a location, such as: C:\Program files\libsvm-3.16

3 assume that you are using a 64-bit operating system and MATLAB. At this point, add the Windows directory under the Libsvm-3.16 folder to the MATLAB directory. The MATLAB directory is added: C:\ProgramFiles\libsvm-3.16\windows. Because of Windows contains MATLAB executable binary file Libsvmread.mexw64/libsvmwrite.mexw64/svmpredict.mexw64/svmtrain.mexw64

4 If you are using a 32-bit operating system and MATLAB, you need to compile the corresponding binaries.

In the MATLAB command window input

>>mex–setup

At this time Matlab will prompt you to choose to compile the Mex file of C + + compiler.

Select one of the C + + compilers installed on your computer, such as Microsoft Visual C + + 2010

The current directory of MATLAB set to: CD ' C:\Program Files\libsvm-3.16\matlab '

Enter command make

At this point you will see that the current directory generates binary file LIBSVMREAD.MEXW32/LIBSVMWRITE.MEXW32/SVMPREDICT.MEXW32/SVMTRAIN.MEXW32. Add the current directory to the MATLAB path.

5 Example a test

Note that there is a data file under Libsvm-3.16, named Heart_scale. This is a LIBSVM format data file. You can use the Libsvmread function to convert it to MATLAB format.

You can use the following code to test:

[Heart_scale_label,heart_scale_inst]=libsvmread (' Heart_scale ');

Model = Svmtrain (Heart_scale_label,heart_scale_inst, '-C 1-g 0.07 ');

[Predict_label, accuracy, dec_values] =svmpredict (Heart_scale_label, heart_scale_inst, model); % test the Trainingdata

6) Svmtrain function Related parameter description

The model returned by the Svmtrain function can be used to predict the test dataset. This is a structural variable, consisting mainly of the following domains. [Parameters, Nr_class, TOTALSV, Rho, Label, ProbA, Probb, Nsv,sv_coef, SVs]. The English description is as follows:

-parameters:parameters

-nr_class:number of classes; = 2 for Regression/one-class SVM

-totalsv:total #SV

-rho:-B of the decision function (s) wx+b

-label:label of each class; Empty for Regression/one-class SVM

-proba:pairwise probability information; Empty if-b 0 or in ONE-CLASSSVM

-probb:pairwise probability information; Empty if-b 0 or in ONE-CLASSSVM

-nsv:number of SVs for each class; Empty for Regression/one-class SVM

-sv_coef:coefficients for SVs in decision functions

-svs:support vectors

If the '-B 1 ' option is not specified, the Proba and Probb are empty matrices. In addition, when the '-V ' option is specified, the returned model is a numeric value, which is the accuracy rate of the cross-validation.

Where the model.paramter is a 5x1 vector, the parameter meaning is:

Model. The parameters parameter meaning is from top to bottom:

-S SVM Type: SVM settings type (default 0)

-T kernel function type: kernel function setting type (default 2)

-D Degree: degree setting in kernel function (for polynomial kernel function) (default 3)

-G R (GAMA): Gamma function setting in kernel function (for polynomial/rbf/sigmoid kernel function) (Reciprocal of default category number)

-R COEF0: COEF0 setting in kernel function (for polynomial/sigmoid kernel function) (default 0)

7) svmpredict function parameter description

The Svmpredict function returns three values, Predict_label, which is the label vector that the training set predicts. The second output is accuracy, is a 3-D vector, from top to bottom is: Classification rate (the parameters used in classification problems), mean square error (MSE (mean squared error)) (regression problem used in the parameter index); the square correlation coefficient (R2 ( Squared correlation coefficient)) (parameter indices used in regression problems). The third output is a matrix that contains the decision value or probability estimate (when ' B 1 ' is specified). When the training data has a K class, the decision value matrix is an n row k* (k-1)/2 column matrix (n is the number of test datasets, K is the category), and the output of each row is the result of the k* (k-1)/2 two classifier. When '-B 1 ' is specified, the probability estimate matrix is a n-row K-Class matrix (n is the number of test datasets, K is a category), and the output of each row is the probability that the test data belongs to each class.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.