forked from jorgecasas/php-ml
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
create docs for StratifiedRandomSplit
- Loading branch information
Showing
4 changed files
with
48 additions
and
2 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
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
44 changes: 44 additions & 0 deletions
44
docs/machine-learning/cross-validation/stratified-random-split.md
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,44 @@ | ||
# Stratified Random Split | ||
|
||
Analogously to `RandomSpilt` class samples are split to two groups: train group and test group. | ||
Distribution of samples takes into account their targets and trying to divide them equally. | ||
You can adjust number of samples in each group. | ||
|
||
### Constructor Parameters | ||
|
||
* $dataset - object that implements `Dataset` interface | ||
* $testSize - a fraction of test split (float, from 0 to 1, default: 0.3) | ||
* $seed - seed for random generator (e.g. for tests) | ||
|
||
``` | ||
$split = new StratifiedRandomSplit($dataset, 0.2); | ||
``` | ||
|
||
### Samples and labels groups | ||
|
||
To get samples or labels from test and train group you can use getters: | ||
|
||
``` | ||
$dataset = new StratifiedRandomSplit($dataset, 0.3, 1234); | ||
// train group | ||
$dataset->getTrainSamples(); | ||
$dataset->getTrainLabels(); | ||
// test group | ||
$dataset->getTestSamples(); | ||
$dataset->getTestLabels(); | ||
``` | ||
|
||
### Example | ||
|
||
``` | ||
$dataset = new ArrayDataset( | ||
$samples = [[1], [2], [3], [4], [5], [6], [7], [8]], | ||
$targets = ['a', 'a', 'a', 'a', 'b', 'b', 'b', 'b'] | ||
); | ||
$split = new StratifiedRandomSplit($dataset, 0.5); | ||
``` | ||
|
||
Split will have equals amount of each target. Two of the target `a` and two of `b`. |