⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 xy2libsvm.m

📁 将二维数据转换成libsvm格式的程序
💻 M
字号:
function xy2svmlight(data,file_name)% XY2LIBSVM Converts data set to LIBSVM format.%% Synopsis:%  xy2libsvm(data,file_name).%% Description:%  This function saves training data to text file required%  by the LIBSVM software. %% Input:%  data.X [ num_data x dim] training data stored as column vectors.%  data.y [ num_data x 1] labels of traning data; possible values %   are 1 (first class) and 2 (second class).%% Output:%  Text file 'file_name' in LIBSVM format.%% See also XY2SVMLIGHT.%% 20-Aug-2007, Freda, createdfid = fopen( file_name, 'w+');dim=size(data.X,2);num_data=size(data.X,1);txt = zeros(1,2*dim);inx1 = 1:2:2*dim;txt(inx1) = 1:dim;inx2 = 2:2:2*dim;for i=1:num_data,  if data.y(i) == 1,     fprintf(fid,'+1 ');   elseif data.y(i) == 2,    fprintf(fid,'-1 ');   else    fprintf(fid,'0 ');   end          txt(inx2) = data.X(i,:);    fprintf( fid, '%d:%f ', txt );  fprintf(fid,'\n');endfclose(fid);return;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -