Total Complexity | 11 |
Total Lines | 41 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | <?php |
||
9 | class TfIdfTransformer implements Transformer |
||
10 | { |
||
11 | /** |
||
12 | * @var array |
||
13 | */ |
||
14 | private $idf = []; |
||
15 | |||
16 | public function __construct(array $samples = []) |
||
17 | { |
||
18 | if (count($samples) > 0) { |
||
19 | $this->fit($samples); |
||
20 | } |
||
21 | } |
||
22 | |||
23 | public function fit(array $samples, ?array $targets = null): void |
||
30 | } |
||
31 | } |
||
32 | |||
33 | public function transform(array &$samples, ?array &$targets = null): void |
||
34 | { |
||
35 | foreach ($samples as &$sample) { |
||
36 | foreach ($sample as $index => &$feature) { |
||
37 | $feature *= $this->idf[$index]; |
||
38 | } |
||
39 | } |
||
40 | } |
||
41 | |||
42 | private function countTokensFrequency(array $samples): void |
||
50 | } |
||
51 | } |
||
52 | } |
||
55 |