1function [CLASS,ERR,POSTERIOR,LOGP,COEF]=classify(sample,training,classlabel,TYPE) 2% CLASSIFY classifies sample data into categories 3% defined by the training data and its group information 4% 5% CLASS = classify(sample, training, group) 6% CLASS = classify(sample, training, group, TYPE) 7% [CLASS,ERR,POSTERIOR,LOGP,COEF] = CLASSIFY(...) 8% 9% CLASS contains the assigned group. 10% ERR is the classification error on the training set weighted by the 11% prior propability of each group. 12% 13% The same classifier as in TRAIN_SC are supported. 14% 15% ATTENTION: no cross-validation is applied, therefore the 16% classification error is too optimistic (overfitting). 17% Use XVAL instead to obtain cross-validated performance. 18% 19% see also: TRAIN_SC, TEST_SC, XVAL 20% 21% References: 22% [1] R. Duda, P. Hart, and D. Stork, Pattern Classification, second ed. 23% John Wiley & Sons, 2001. 24 25% $Id$ 26% Copyright (C) 2008,2009 by Alois Schloegl <alois.schloegl@gmail.com> 27% This function is part of the NaN-toolbox 28% http://pub.ist.ac.at/~schloegl/matlab/NaN/ 29 30% This program is free software; you can redistribute it and/or 31% modify it under the terms of the GNU General Public License 32% as published by the Free Software Foundation; either version 3 33% of the License, or (at your option) any later version. 34% 35% This program is distributed in the hope that it will be useful, 36% but WITHOUT ANY WARRANTY; without even the implied warranty of 37% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 38% GNU General Public License for more details. 39% 40% You should have received a copy of the GNU General Public License 41% along with this program; if not, write to the Free Software 42% Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. 43 44if nargin<4 45 TYPE = 'linear'; 46end; 47 48if strcmp(TYPE,'linear') 49 TYPE = 'LDA'; 50elseif strcmp(TYPE,'quadratic') 51 TYPE = 'QDA2'; % result is closer to Matlab 52elseif strcmp(TYPE,'diagLinear') 53 TYPE = 'NBC'; 54elseif strcmp(TYPE,'diagQuadratic') 55 TYPE = 'NBC'; 56elseif strcmp(TYPE,'mahalanobis') 57 TYPE = 'MDA'; 58end; 59 60[group,I,classlabel] = unique(classlabel); 61 62CC = train_sc(training,classlabel,TYPE); 63R = test_sc(CC,sample); 64CLASS = group(R.classlabel); 65 66if nargout>1, 67 R = test_sc(CC,training,[],classlabel); 68 ERR = 1-R.ACC; 69end; 70 71if nargout>2, 72 warning('output arguments POSTERIOR,LOGP and COEF not supported') 73 POSTERIOR = []; 74 LOGP = []; 75 COEF = []; 76end; 77 78