-
-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
data splitter unit tests split up into bunch of micro tests, CrossVal…
…idator initializing refactored
- Loading branch information
Showing
8 changed files
with
161 additions
and
176 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
12 changes: 2 additions & 10 deletions
12
lib/src/model_selection/cross_validator/cross_validator_impl.dart
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
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
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
This file was deleted.
Oops, something went wrong.
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,69 @@ | ||
import 'package:ml_algo/src/model_selection/data_splitter/k_fold.dart'; | ||
import 'package:test/test.dart'; | ||
|
||
void main() { | ||
group('KFold splitter', () { | ||
void testKFoldSplitter(int numOfFold, int numOfObservations, | ||
Iterable<Iterable<int>> expected) { | ||
test('should return proper groups of indices if number of folds is ' | ||
'$numOfFold and number of observations is $numOfObservations', () { | ||
final splitter = KFoldSplitter(numOfFold); | ||
expect(splitter.split(numOfObservations), equals(expected)); | ||
}); | ||
} | ||
|
||
test('should throw an exception if passed number of folds is equal to ' | ||
'0', () { | ||
expect(() => KFoldSplitter(0), throwsRangeError); | ||
}); | ||
|
||
test('should throw an exception if passed number of folds is equal to ' | ||
'1', () { | ||
expect(() => KFoldSplitter(1), throwsRangeError); | ||
}); | ||
|
||
testKFoldSplitter(5, 12, [ | ||
[0, 1], | ||
[2, 3], | ||
[4, 5], | ||
[6, 7, 8], | ||
[9, 10, 11], | ||
]); | ||
|
||
testKFoldSplitter(4, 12, [ | ||
[0, 1, 2], | ||
[3, 4, 5], | ||
[6, 7, 8], | ||
[9, 10, 11], | ||
]); | ||
|
||
testKFoldSplitter(3, 12, [ | ||
[0, 1, 2, 3], | ||
[4, 5, 6, 7], | ||
[8, 9, 10, 11], | ||
]); | ||
|
||
testKFoldSplitter(12, 12, [ | ||
[0], [1], [2], [3], [4], [5], [6], [7], [8], [9], [10], [11], | ||
]); | ||
|
||
testKFoldSplitter(5, 37, [ | ||
[0, 1, 2, 3, 4, 5, 6], | ||
[7, 8, 9, 10, 11, 12, 13], | ||
[14, 15, 16, 17, 18, 19, 20], | ||
[21, 22, 23, 24, 25, 26, 27, 28], | ||
[29, 30, 31, 32, 33, 34, 35, 36], | ||
]); | ||
|
||
test('should throws a range error if number of observations is 0', () { | ||
final splitter = KFoldSplitter(3); | ||
expect(() => splitter.split(0), throwsRangeError); | ||
}); | ||
|
||
test('should throws a range error if number of observations is less than' | ||
'number of folds', () { | ||
final splitter = KFoldSplitter(9); | ||
expect(() => splitter.split(8), throwsRangeError); | ||
}); | ||
}); | ||
} |
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,69 @@ | ||
import 'package:ml_algo/src/model_selection/data_splitter/leave_p_out.dart'; | ||
import 'package:test/test.dart'; | ||
|
||
void main() { | ||
group('Leave p out splitter', () { | ||
void testLpoSplitter(int p, int numOfObservations, | ||
Iterable<Iterable<int>> expected) { | ||
test('should return proper groups of indices if p is $p and number of ' | ||
'observations is $numOfObservations', () { | ||
final splitter = LeavePOutSplitter(p); | ||
expect(splitter.split(numOfObservations).toSet(), equals(expected)); | ||
}); | ||
} | ||
|
||
testLpoSplitter(2, 4, [ | ||
[0, 1], | ||
[0, 2], | ||
[0, 3], | ||
[1, 2], | ||
[1, 3], | ||
[2, 3], | ||
].toSet()); | ||
|
||
testLpoSplitter(2, 5, [ | ||
[0, 1], | ||
[0, 2], | ||
[0, 3], | ||
[0, 4], | ||
[1, 2], | ||
[1, 3], | ||
[1, 4], | ||
[2, 3], | ||
[2, 4], | ||
[3, 4], | ||
].toSet()); | ||
|
||
testLpoSplitter(1, 5, [ | ||
[0], | ||
[1], | ||
[2], | ||
[3], | ||
[4], | ||
].toSet()); | ||
|
||
testLpoSplitter(3, 4, [ | ||
[0, 1, 2], | ||
[0, 1, 3], | ||
[0, 2, 3], | ||
[1, 2, 3], | ||
].toSet()); | ||
|
||
testLpoSplitter(3, 5, [ | ||
[0, 1, 2], | ||
[0, 1, 3], | ||
[0, 1, 4], | ||
[0, 2, 3], | ||
[0, 2, 4], | ||
[0, 3, 4], | ||
[1, 2, 3], | ||
[1, 2, 4], | ||
[1, 3, 4], | ||
[2, 3, 4], | ||
].toSet()); | ||
|
||
test('should throw an error, if p is equal to 0', () { | ||
expect(() => LeavePOutSplitter(0), throwsUnsupportedError); | ||
}); | ||
}); | ||
} |
Oops, something went wrong.