📄 write_svm_data.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 + -