Predicting Mortality of ICU Patients: The PhysioNet/Computing in Cardiology Challenge 2012 1.0.0
(1,653 bytes)
function [outclass, prob] = svmclassify_ML(svmStruct,sample)
%SVMCLASSIFY classifies data using a support vector machine
%
% GROUP = SVMCLASSIFY(SVMStruct,SAMPLE) classifies each row of the data
% in SAMPLE using the information in a support vector machine classifier
% structure SVMStruct created using SVMTRAIN. SAMPLE must have the same
% number of columns as the data used to train the classifier in SVMTRAIN.
% GROUP indicates the group to which each row of SAMPLE is assigned.
% check inputs
bioinfochecknargin(nargin,2,mfilename);
% deal with struct input case
if ~isstruct(svmStruct)
error('Bioinfo:svmclassify:TwoInputsNoStruct',...
'The first input should be a struct generated by SVMTRAIN.');
end
groupnames = svmStruct.GroupNames;
% check group is a vector -- though char input is special...
if ~isvector(groupnames) && ~ischar(groupnames)
error('Bioinfo:svmclassify:GroupNotVector',...
'Group must be a vector.');
end
% grp2idx sorts a numeric grouping var ascending, and a string grouping
% var by order of first occurrence
[g,groupString] = grp2idx(groupnames);
% do the classification
if ~isempty(sample)
% shift and scale the data if necessary:
if ~isempty(svmStruct.ScaleData)
for i = 1:size(sample,1)
sample(i,:) = sample(i,:)./svmStruct.ScaleData;
end
end
try
[outclass, prob] = svmdecision_ML(sample,svmStruct);
catch theException
error('Bioinfo:svmclassify:ClassifyFailed',...
'An error was encountered during classification.\n%s',theException.message);
end
else
outclass = [];
prob = [];
end