开发者

Transform input file in matlab adding values, or replacing and save it to other file

I am using libsvm, and would like to train some data, the issue here is, libsvm ask the input patterns in a special format.

Let be my file:

    72,0,5.6431,28.19,34.398,0.00662,3.38005,0.00401,0.00317,0.01204,0.02565,1
    58,0,5.8600,77.7 ,19.317,0.00793,6.39105,0.00379,0.00385,0.01136,0.03751,2

Where

  • last '1' (last column) in first row represent the class
  • last '2' (last column) in second row represent other class

Let be the format libsvm asks for (taken from heart_scale example file):

+1 1:0.708333 2:1  3:1            4:-0.320755 5:-0.105023 6:-1 7:1   8:-0.419847 9:-1 10:-0.225806 12:1   13:-1 
-1 1:0.583333 2:-1 3:0.333333     4:-0.603774 5:1         6:-1 7:1   8:0.358779  9:-1 10:-0.483871 12:-1  13:1 
+1 1:0.166667 2:1  3:-0.333333    4:-0.433962 5:-0.383562 6:-1 7:-1  8:0.068开发者_JAVA百科7023 9:-1 10:-0.903226 11:-1  12:-1 13:1 

How could you load or put in libsvm format the input file? or change the last column for the first?, changing ',' for column number and ':'?? I forgot saying that for libsvm the first column represents the class...


Libsvm provides a C code which you can compile and use to easily transform your features into libsvm format. (download link: http://www.csie.ntu.edu.tw/~cjlin/libsvm/faqfiles/convert.c) In your case, however, you must first place the class id (1-2) in the beginning of each file. Each line of the input text file should look like this: 0,-6.5012,-2.874

The first value is the class label and the rest are feature values.

./convert_compiled feat.txt > svm_format_feat.txt

the the corresponding output line will be:

0 1:-6.501200 2:-2.874000

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜