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

📄 write_svm_data.m

📁 最新的模式识别分类工具箱,希望对朋友们有用!
💻 M
字号:
function make_svmdata(features, labels, filename)

%Make a BSVM-format data file from a features matrix 
%Inputs:
%	features - A matrix of features of size #features x #points
%  labels   - A vector of labels (targets) corresponding to the 
%				  number of points in the features matrix
%	filename - The name of the file to be created

if (size(features,2) ~= length(labels)),
   error('Features and labels do not match in length!');
end


fid = fopen(filename, 'w');
if (fid == -1),
   error('Could not open the file');
end

[c,r] = size(features);

for i = 1:r,
   %Write the label
   if (labels(i) < 1)
      fprintf(fid, '-1 ');
   else
      fprintf(fid, '+1 ');
   end
   for j=1:c,
      fprintf(fid, '%i:%f ', j, features(j,i));
   end
   fprintf(fid, char(13));
   fprintf(fid, char(10));
end

fclose(fid);

⌨️ 快捷键说明

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