inputFormat
============
28.7967,16.0021,2.6449,0.3918,0.1982,27.7004,22.011,-8.2027,40.092,81.8828,g
svmFormat
=============
g 1:28.796700 2:16.002100 3:2.644900 4:0.391800 5:0.198200 6:27.700400 7:22.011000 8:-8.202700 9:40.092000 10:81.882800
code
=======
fid = fopen('magic04.data','r');
raw_data = textscan(fid,'%f %f %f %f %f %f %f %f %f %f %c','delimiter',',');
data = [raw_data{1:10}];
class = raw_data{11};
fclose(fid);
svmTrain = fopen( 'magic04.data.svm' ,'w');
noRow = size(data,1);
noCol = size(data,2);
for r=1:noRow
label = class(r);
fprintf(svmTrain,'%s\t',label );
for c=1:noCol
fprintf(svmTrain,'%d:%f\t',c,data(r,c) );
end
fprintf(svmTrain,'\n' );
end
fclose(svmTrain);
Comments
Post a Comment