Skip to content

Commit

Permalink
Added test_predictOneVsAll
Browse files Browse the repository at this point in the history
  • Loading branch information
cod3monk3y committed Apr 4, 2014
1 parent e72816b commit 749c621
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
2 changes: 2 additions & 0 deletions ex3/test_ex3.m
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
%!test test_sanity()

%!test test_oneVsAll()

%!test test_predictOneVsAll()
24 changes: 24 additions & 0 deletions ex3/test_predictOneVsAll.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
function test_predictOneVsAll ()
epsilon = 1e-3;

% learning three classes
%
% x < 1.5 => 1
% 1.5 < x < 3.5 => 2
% 3.5 < x => 3
%
X = [0 1 2 3 4 5]';
y = [1 1 2 2 3 3]'; % direct classification
num_labels = 3;

all_theta = oneVsAll(X, y, num_labels, 0);
assert(size(all_theta), [3 2]);

yy = predictOneVsAll(all_theta, X);
assert(yy, y);

% predict ones we haven't seen yet (should match the original formula)
X = [-10 2.5 10.0]';
assert(predictOneVsAll(all_theta, X), [1 2 3]');

endfunction

0 comments on commit 749c621

Please sign in to comment.