Completed
Push — develop ( 021320...f04cc0 )
by Arkadiusz
03:15
created

RandomSplit::getTrainLabels()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
declare (strict_types = 1);
4
5
namespace Phpml\CrossValidation;
6
7
use Phpml\Dataset\Dataset;
8
9
class RandomSplit extends Split
10
{
11
    /**
12
     * @param Dataset $dataset
13
     * @param float   $testSize
14
     */
15
    protected function splitDataset(Dataset $dataset, float $testSize)
16
    {
17
        $samples = $dataset->getSamples();
18
        $labels = $dataset->getTargets();
19
        $datasetSize = count($samples);
20
        $testCount = count($this->testSamples);
21
22
        for ($i = $datasetSize; $i > 0; --$i) {
23
            $key = mt_rand(0, $datasetSize - 1);
24
            $setName = (count($this->testSamples) - $testCount) / $datasetSize >= $testSize ? 'train' : 'test';
25
26
            $this->{$setName.'Samples'}[] = $samples[$key];
27
            $this->{$setName.'Labels'}[] = $labels[$key];
28
        }
29
    }
30
}
31