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

RandomSplit   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 4
Bugs 0 Features 1
Metric Value
wmc 3
c 4
b 0
f 1
lcom 1
cbo 2
dl 0
loc 22
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A splitDataset() 0 15 3
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