Skip to content

Commit

Permalink
create docs for StratifiedRandomSplit
Browse files Browse the repository at this point in the history
  • Loading branch information
akondas committed Jul 10, 2016
1 parent f04cc04 commit ee6ea3b
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 2 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ composer require php-ai/php-ml
* [Accuracy](http://php-ml.readthedocs.io/en/latest/machine-learning/metric/accuracy/)
* Cross Validation
* [Random Split](http://php-ml.readthedocs.io/en/latest/machine-learning/cross-validation/random-split/)
* [Stratified Random Split](http://php-ml.readthedocs.io/en/latest/machine-learning/cross-validation/stratified-random-split/)
* Preprocessing
* [Normalization](http://php-ml.readthedocs.io/en/latest/machine-learning/preprocessing/normalization/)
* [Imputation missing values](http://php-ml.readthedocs.io/en/latest/machine-learning/preprocessing/imputation-missing-values/)
Expand Down
1 change: 1 addition & 0 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ composer require php-ai/php-ml
* [Accuracy](http://php-ml.readthedocs.io/en/latest/machine-learning/metric/accuracy/)
* Cross Validation
* [Random Split](http://php-ml.readthedocs.io/en/latest/machine-learning/cross-validation/random-split/)
* [Stratified Random Split](http://php-ml.readthedocs.io/en/latest/machine-learning/cross-validation/stratified-random-split/)
* Preprocessing
* [Normalization](http://php-ml.readthedocs.io/en/latest/machine-learning/preprocessing/normalization/)
* [Imputation missing values](http://php-ml.readthedocs.io/en/latest/machine-learning/preprocessing/imputation-missing-values/)
Expand Down
4 changes: 2 additions & 2 deletions docs/machine-learning/cross-validation/random-split.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# RandomSplit
# Random Split

One of the simplest methods from Cross-validation is implemented as `RandomSpilt` class. Samples are split to two groups: train group and test group. 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 (for tests)
* $seed - seed for random generator (e.g. for tests)

```
$randomSplit = new RandomSplit($dataset, 0.2);
Expand Down
44 changes: 44 additions & 0 deletions docs/machine-learning/cross-validation/stratified-random-split.md
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`.

0 comments on commit ee6ea3b

Please sign in to comment.