LIBSVM Study (iii)--LIBSVM usage specification

Source: Internet
Author: User
Tags svm

In fact, this part of the write is superfluous, Google a little "LIBSVM use", will be n more resources, but, in order to let you less cost dim sum, here on a simple introduction, there is not clear only to move your mouse. It should be explained that, before the 2.89 version, are Svmscale, Svmtrain and Svmpredict, the latest is Svm-scale, Svm-train and svm-predict, if not used to, Only need to remove the four EXE file name in the middle of the short horizontal line, change to Svmscale, Svmtrain and svmpredict on it, we still according to the original function name of the said.

1. LIBSVM data Format

Label 1:value 2:value ....

Label: is the identification of the category, such as the previous section Train.model mentioned in the 1-1, you can set your own, such as -10,0,15. Of course, if it is a return, this is the target value, it is necessary to be realistic.

Value: Is the data to be trained, from the point of view of the classification is the eigenvalues, the data separated by a space

For example:-15 1:0.708 2:1056 3:-0.3333

It is important to note that if the eigenvalue is 0, the preceding (or the ordinal ) of a characteristic colon can be discontinuous. Such as:

-15 1:0.708 3:-0.3333

Indicates that the 2nd eigenvalue is 0, from a programming point of view, this can reduce the use of memory, and improve the operation speed of the matrix inside product. We usually produce in MATLAB data are no serial number of the regular matrix, so in order to facilitate the best programming a program for conversion.

2. usage of Svmscale

Svmscale is used to scale the original sample, the range can be self-determined, generally [0,1] or [ -1,1]. The purpose of scaling is mainly

1) Prevent a feature from being too large or too small to play an unbalanced role in training;

2) in order to calculate the speed. Because in nuclear calculations, an internal product operation or an exp operation is used, unbalanced data can cause computational difficulties.

Usage: svmscale [-l lower] [-u Upper]

[-y Y_lower Y_upper]

[-S Save_filename]

[-R Restore_filename] FileName

where, [] are available in the options:

-L: Set data lower limit, lower: Set data low value, default is-1

-U: Set data limit, upper: Set data limit value, default is 1

-Y: Whether the target value is scaled at the same time; Y_lower is the lower value and Y_upper is the upper limit;

-S Save_filename: Indicates that the scaling rule is saved as a file save_filename;

-R Restore_filename: Indicates that it will be scaled according to the existing rule file restore_filename;

FileName: Data file to be scaled, file format according to LIBSVM format.

By default, you only need to enter the file name you want to scale: for example (the file that already exists is test.txt)

Svmscale Test.txt

At this point, the data in the Test.txt has become the data between [ -1,1]. However, so that the original data is overwritten, in order to save the planned data as other files, we use a DOS redirect > to save As (assuming OUT.txt):

Svmscale test.txt > OUT.txt

After running, we can see a directory of more than one OUT.txt file, that is the canonical data. If we want to set the data range [0,1] and save the rule as a Test.range file:

Svmscale–l 0–u 1–s test.range test.txt > OUT.txt

At this time, there is another Test.range file in the directory, you can open it with Notepad, you can use the-R test.range to load.

3. usage of Svmtrain

Svmtrain we have been in touch before, he mainly realizes training data set training, and can obtain the SVM model.

Usage: svmtrain [options] training_set_file [Model_file]

Where options are the operating parameters, the option that is available is the meaning of the following:

-S set the SVM type:

0–c-svc

1–v-svc

2–one-class-svm

3–ε-svr

4–n-svr

-T sets the kernel function type, the default value is 2

0--Linear core:u' *v

1--Polynomial core: (g*u' *v+ coef 0) degree

2--RBF Core:exp(-γ*| | u-v| | 2)

3--sigmoid core: Tanh (γ*u' *v+ coef 0)

-D Degree: Sets the value of degree in the polynomial core, which defaults to 3

-gγ: Sets the value of gamma in the kernel function, the default is 1/k,k is the number of features (or attributes);

-R COEF 0: sets the Coef 0 in the kernel function, the default value is 0;

-C Cost: Set C-svc, Ε-svr, n-svr from the penalty factor C, the default value is 1;

-N V: Set v-svc, ONE-CLASS-SVM and n-svr in parameter n, default value 0.5;

-pε: Set E in the loss function of V-SVR, the default value is 0.1;

-M CacheSize: Sets the cache memory size, in megabytes, the default value is 40;

-eε: Set the tolerable deviation in the termination criteria, the default value is 0.001;

-H Shrinking: Whether heuristic is used, optional value is 0 or 1, default value is 1;

-B probability estimate: whether to calculate the probability estimate of Svc or SVR, optional value 0 or 1, default 0;

-wi weight: The penalty coefficient C weighted for each kind of sample, the default value is 1;

-V N/a folded cross-validation mode;

Model_file: Optional, the result file to be saved, called the model file, for use during prediction.

By default, you only need to provide a sample file name to the function, but in order to save the result, or to provide a result file name, such as: Test.model, the command is:

Svmtrain Test.txt Test.model

Results show LIBSVM Study (II.).

4. usage of svmpredict

Svmpredict is a model that is based on training and predicts the set of data.

Usage: svmpredict [options] Test_file model_file output_file

Where options are the operating parameters, the option that is available is the meaning of the following:

The-B probability_estimates--whether a probability estimation prediction is required, an optional value of 0 or 1, and a default value of 0.

model_file--is a model file produced by Svmtrain;

test_file--is the data file to be predicted, the format must conform to the LIBSVM format, even if you do not know the value of the label, but also to fill in any one, svmpredict will give the correct label results in Output_file, if you know the value of the label, It will output the correct rate;

output_file--is the output file of Svmpredict, which represents the predicted result value.

At this point, the main interface has been finished, to meet the general application is not a problem. For research, you need to go deep inside the svm.cpp file and see what you've done.

LIBSVM Learning (iii)--LIBSVM Usage specification (EXT)

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.