-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e72816b
commit 749c621
Showing
2 changed files
with
26 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
%!test test_sanity() | ||
|
||
%!test test_oneVsAll() | ||
|
||
%!test test_predictOneVsAll() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |