Mercurial > forge
annotate extra/NaN/test/test_xval.m @ 12583:21f4d96c4959 octave-forge
[nan] modify tests
author | schloegl |
---|---|
date | Fri, 03 Apr 2015 19:24:06 +0000 |
parents | 41f92a4ada86 |
children |
rev | line source |
---|---|
6530 | 1 % test_classifier; |
2 | |
3 % $Id$ | |
8037 | 4 % Copyright (C) 2010 by Alois Schloegl <alois.schloegl@gmail.com> |
6530 | 5 % This function is part of the NaN-toolbox |
8037 | 6 % http://pub.ist.ac.at/~schloegl/matlab/NaN/ |
6530 | 7 |
8 % This program is free software; you can redistribute it and/or | |
9 % modify it under the terms of the GNU General Public License | |
10 % as published by the Free Software Foundation; either version 3 | |
11 % of the License, or (at your option) any later version. | |
12 % | |
13 % This program is distributed in the hope that it will be useful, | |
14 % but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 % GNU General Public License for more details. | |
17 % | |
18 % You should have received a copy of the GNU General Public License | |
19 % along with this program; if not, write to the Free Software | |
8165 | 20 % Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. |
6530 | 21 |
22 | |
6541
4bec4452a4b9
{-1,+1} encoding of classlabel supported; test of liblinear and libSVM with Octave3.2
schloegl
parents:
6530
diff
changeset
|
23 if 1, |
6530 | 24 clear |
6787
64a859a65534
update website, svn keywords, prepare for next release
schloegl
parents:
6543
diff
changeset
|
25 N=100; % number of samples |
64a859a65534
update website, svn keywords, prepare for next release
schloegl
parents:
6543
diff
changeset
|
26 M=10; % number of features |
64a859a65534
update website, svn keywords, prepare for next release
schloegl
parents:
6543
diff
changeset
|
27 classifier= {'SVM:LIB','REG','MDA','MD2','QDA','QDA2','LD2','LD3','LD4','LD5','LD6','NBC','aNBC','WienerHopf','LDA/GSVD','MDA/GSVD', 'LDA/sparse','MDA/sparse', 'PLA', 'LMS','LDA/DELETION','MDA/DELETION','NBC/DELETION','RDA/DELETION','REG/DELETION','RDA','GDBC','SVM','RBF','PSVM','SVM11','SVM:LIN4','SVM:LIN0','SVM:LIN1','SVM:LIN2','SVM:LIN3','WINNOW'}; |
12583 | 28 %classifier= {'SVM:RBF'}; |
6530 | 29 |
6787
64a859a65534
update website, svn keywords, prepare for next release
schloegl
parents:
6543
diff
changeset
|
30 x = randn(N,M); % data |
64a859a65534
update website, svn keywords, prepare for next release
schloegl
parents:
6543
diff
changeset
|
31 c = ([1:N]'>(N/2))+1; % classlabel |
6530 | 32 %w = [ones(1,N/2)/5,ones(1,N/10),zeros(1,4*N/10)]; |
6787
64a859a65534
update website, svn keywords, prepare for next release
schloegl
parents:
6543
diff
changeset
|
33 w = []; % no weightening |
6530 | 34 |
35 x = randn(N,M); | |
36 x = x+c*ones(1,M); | |
37 | |
6787
64a859a65534
update website, svn keywords, prepare for next release
schloegl
parents:
6543
diff
changeset
|
38 if 1, |
6541
4bec4452a4b9
{-1,+1} encoding of classlabel supported; test of liblinear and libSVM with Octave3.2
schloegl
parents:
6530
diff
changeset
|
39 %x(2:2:N/2,2) = NaN; |
4bec4452a4b9
{-1,+1} encoding of classlabel supported; test of liblinear and libSVM with Octave3.2
schloegl
parents:
6530
diff
changeset
|
40 x(2:2:N,2) = NaN; |
6530 | 41 x(3,2:2:end) = NaN; |
6541
4bec4452a4b9
{-1,+1} encoding of classlabel supported; test of liblinear and libSVM with Octave3.2
schloegl
parents:
6530
diff
changeset
|
42 end; |
6787
64a859a65534
update website, svn keywords, prepare for next release
schloegl
parents:
6543
diff
changeset
|
43 end; |
6530 | 44 |
6543 | 45 for k = 1:length(classifier); |
46 try, | |
6541
4bec4452a4b9
{-1,+1} encoding of classlabel supported; test of liblinear and libSVM with Octave3.2
schloegl
parents:
6530
diff
changeset
|
47 [R{k},CC{k}] = xval(x, {c,w}, classifier{k}); |
6787
64a859a65534
update website, svn keywords, prepare for next release
schloegl
parents:
6543
diff
changeset
|
48 fprintf(1,'%8s\t%i\t%5.2f\t%5.2f+-%5.2f\n',classifier{k},sum(R{k}.data(:)),R{k}.ACC*100,R{k}.kappa,R{k}.kappa_se); |
64a859a65534
update website, svn keywords, prepare for next release
schloegl
parents:
6543
diff
changeset
|
49 save -v6 debug.mat |
6543 | 50 catch, |
51 R{k} = []; | |
52 end; | |
6530 | 53 end; |
54 | |
55 for k = 1:length(R) | |
56 if isempty(R{k}) | |
57 fprintf(1,'%8s \t failed\n',classifier{k}); | |
58 else | |
59 fprintf(1,'%8s\t%i\t%5.2f\t%5.2f+-%5.2f\n',classifier{k},sum(R{k}.data(:)),R{k}.ACC*100,R{k}.kappa,R{k}.kappa_se); | |
60 end; | |
61 end | |
62 |