Conditions | 5 |
Paths | 8 |
Total Lines | 24 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | <?php |
||
9 | public static function compute(array $actualLabels, array $predictedLabels, array $labels = []): array |
||
10 | { |
||
11 | $labels = count($labels) === 0 ? self::getUniqueLabels($actualLabels) : array_flip($labels); |
||
12 | $matrix = self::generateMatrixWithZeros($labels); |
||
13 | |||
14 | foreach ($actualLabels as $index => $actual) { |
||
15 | $predicted = $predictedLabels[$index]; |
||
16 | |||
17 | if (!isset($labels[$actual], $labels[$predicted])) { |
||
18 | continue; |
||
19 | } |
||
20 | |||
21 | if ($predicted === $actual) { |
||
22 | $row = $column = $labels[$actual]; |
||
23 | } else { |
||
24 | $row = $labels[$actual]; |
||
25 | $column = $labels[$predicted]; |
||
26 | } |
||
27 | |||
28 | ++$matrix[$row][$column]; |
||
29 | } |
||
30 | |||
31 | return $matrix; |
||
32 | } |
||
33 | |||
54 |