AbstractNormalization::normalizeDataset()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 14
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 11
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 14
ccs 11
cts 11
cp 1
rs 9.4285
cc 2
eloc 9
nc 2
nop 2
crap 2
1
<?php
2
3
namespace MachineLearning\Application\Normalization;
4
5
use MachineLearning\Domain\Model\Dataset;
6
use MachineLearning\Domain\Model\ValueInterface;
7
8
9
abstract class AbstractNormalization implements NormalizationInterface
10
{
11
    /**
12
     * @inheritdoc
13
     */
14 1
    public function normalizeDataset(Dataset $data, ValueInterface $coefficient)
15
    {
16 1
        $normalizedData = [];
17 1
        foreach ($data as $row) {
18 1
            $features = $row->getIndependentVariable();
19 1
            $features = $this->normalizeValue($features, $coefficient);
20 1
            $normalizedData[] = [
21 1
                $features->getValue(),
22 1
                $row->getDependentVariable()->getValue()
23 1
            ];
24 1
        }
25
26 1
        return new Dataset($normalizedData, $data->getHypothesis());
27
    }
28
29
    /**
30
     * @inheritdoc
31
     */
32
    abstract public function normalizeValue(ValueInterface $value, ValueInterface $coefficient);
33
}