First introduce the data format of LIBSVM
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 arbitrarily set, 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 first 2 eigenvalues are 0, from a programmatic point of view, this reduces the use of memory and increases the computational speed of the inner product of the matrix. 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.
How to generate the data format used by LIBSVM
The first method uses Formatdatalibsvm.xls
I have saved in my Baidu net disk inside, can download for free ~ Remember before is in Sina Love asks to download, need integral ...
To http://pan.baidu.com/share/link?shareid=447079&uk=2165237662
Run Formatdatalibsvm.xls (note that there will be a "macro banned macro" security alert, click on "Options", select "Enable this content", OK);1, run first Formatdatalibsvm.xls then pastes the data into the Sheet1 topleft unit.
2, open Data.xls, (note: Many of the online introduction is to paste the data directly into the Sheet1 topleft unit ), to pay special attention to this time the data order should be:
Condition attribute A condition property b ... Decision Properties
7 5 ... 2
4 2 ... 1
3."Tools"--" macro"-- Execute below an option (FORMATDATATOLIBSVM)--to select this and then click "Run", this time the data becomes:
Decision attribute condition attribute A condition property b ...
2 1:7 2:5 ...
1 1:4 2:2 ...
When the data conversion is complete, save the file as a . txt file. Then the problem of data conversion is solved.
The second method of
. txt format ->SVM format conversion (this segment goes from http://blog.csdn.net/lztao82/article/details/7495258)
First of all, the text data mentioned here refers to data files with commas, spaces, comma, semicolons and other data separation symbols. Because it is separated by a symbol, all data items are categorized as an attribute and cannot be entered in the format of the above 2 steps, and the output of the correct result format cannot be achieved.
To solve this problem, the most significant difference between the conversion process and the previous one is that when you open the. txt file, the data from the text data itself is separated from the comma, semicolon, tab, and so on. Formatdatalibsvm.xls, file,Open,Select the Data,txt file you want to open , and then in the Text Import Wizard, Select the Data feature of the Data.txt file itself. Original data type (delimited) "; then select the type of the delimited symbol (the goal is to make the data into separate columns of column data, if the separation succeeds, in the data preview you will see a column of columns separating separate data): Select" Column Data Format "(general),complete;
This time just adjust the data format of the "one" process above, repeat steps 2, 3 after theoperation.
The third method of
in fact, LIBSVM required data can be generated by themselves ~ For example, I used to use the Image Color feature for image segmentation, first read the RGB value with the program and then saved in the TXT file can be ~ Just pay attention to the saved format
How to use this data
Take simple use as an example
In the case of an example Heart_scale.mat with LIBSVM , everything is normal ~
Load Heart_scale.mat (no semicolon here)
train = Heart_scale_inst;
Train_label=heart_scale_label;
Test=train;
Test_label=train_label;
Model=svmtrain (Train_label,train, '-C 2-g 0.01 ');
[Predict_label,accuracy]=svmpredict (Test_label,test,model);
But there's a problem when we use our own example .
Because train = Heart_scale_inst; is the feature column of the mat file
Train_label=heart_scale_label a label column for a mat file
The txt or mat file that we generated has not yet been assigned so it can be assigned at the beginning ~
A=[newmat (1:2288,1:3)];% feature column
B=[newmat (1:2288,4)];% label column
train = A;
Train_label=b;
Data format for LIBSVM